Entity Framework and the missing class EntityConfiguration<!-- --> | <!-- -->Patrick Desjardins Blog
Patrick Desjardins Blog
Patrick Desjardins picture from a conference

Entity Framework and the missing class EntityConfiguration

Posted on: March 17, 2012

Many blogs were written with EntityConfiguration class which doesn't exist in EF4.1 release version and above.

If you need to do the mapping of your properties with table columns, you should not use EntityTypeConfiguration or ComplexTypeConfiguration class. Those classes are in the namespace System.Data.Entity.ModelConfiguration.

This will let you in your DbContext class to override the method OnModelCreating and to set the configuration desired.

1protected override void OnModelCreating(DbModelBuilder modelBuilder) {
2 //...
3 modelBuilder.Configurations.Add(new MyClassConfiguration());
4 base.OnModelCreating(modelBuilder);
7//In an other class:
8public class MyClassConfiguration: EntityTypeConfiguration<MyClass> {
9 public MyClassConfiguration() {
10 ToTable("MySuperOtherNameTable");
11 Property(c => c.Code).HasColumnName("Code_Col1");
12 Property(c => c.Name).HasColumnName("Name_FR_CANADA");
13 }

This let you have Entity Framework on a database that has been constructed without having the same name of your model. This use the Fluent interface of Entity Framework to accomplish this task. EF let you do it by attribute also (this will be discussed later). Of course, this require more manual labour but can be great to by pass some objects, one object or even a part of an object. Indeed, this can be use only on few properties of your object and let Entity Framework handle the rest of your object automatically.