Patrick Desjardins Blog
Patrick Desjardins picture from a conference

How to rename complex type to not having the prefix of the class name

Posted on: 2013-06-13

Entity Framework has a standard with the naming of column. This is also the case with complex type which will be added to every tables where complex type are used by entities. By default, Entity Framework will concatenate the name of the complex type with an underscore and the name of the property.

If you prefer not having complex type name, you can simply specify the column name you desire.

 modelBuilder .ComplexType<Audit>()
 .Property(type => type.CreatedBy)
 .HasColumnName("CreatedBy"); 

In the database instead of having a field with "Audit_CreatedBy" you will have only "CreatedBy". This may be useful in some situation, but by experience it's easier to do the mapping between complex type when you keep the prefix. It's up to you, and your coding/database standard, to figure out if it's appropriate or not.