How to rename complex type to not having the prefix of the class name
Posted on: June 13, 2013
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.
1modelBuilder .ComplexType<Audit>()2 .Property(type => type.CreatedBy)3 .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.