Home » Ado.Net » Entity Framework » How to rename complex type to not having the prefix of the class name

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

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.

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

One Response so far.

  1. […] class will be complex and will be directly added into all tables when used. This is the case for the Money and for the […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.