I’ve just started to implement EF CTP 5 in to a new project. In this case all my database fields are named differently to my POCO properties due to an obscure database naming convention. Am I right in thinking the best way to map this is to override OnModelCreating and have code like this
modelBuilder.Entity<Sale>().Property(s => s.ID).HasColumnName("sale_id");
modelBuilder.Entity<Sale>().Property(s => s.ProductName).HasColumnName("product_name");
modelBuilder.Entity<Sale>().Property(s => s.ProductPrice).HasColumnName("product_price");
modelBuilder.Entity<Sale>().Property(s => s.SaleDate).HasColumnName("sale_date");
This is going to end up very large very quick, is it really the best way to do this?
Thanks for the answers
I ended up sticking with my original approach as I wanted to keep the entities seperate from the data layer.
However to make it more manageable I made the context a partial class and created a file for each entity with a private method like MapUsers or MapRoles then in the OnModelCreating I just called these methods.