EF CTP5 card primary key with a different column name

The property has a free method called HasColumnName. HasKey is not enough. In CTP4, it was possible to specify different column names through MapSingleType, but if I try to use Map (which replaced MapSingleType), this will not work. Any ideas?

+4
source share
2 answers

Does this work?

modelBuilder.Entity<Institutes.Institute>() .HasKey(e => e.Id) .ToTable("Institutes", "core"); modelBuilder.Entity<Institutes.Institute>().Property(e => e.Id) .HasColumnName("InstituteID"); 
+2
source

The CTP5 API does not seem to offer such a feature. We will be able to do this to allow ModelBuilder to build a MetaDataWorkspace with the wrong key.

Then, after it was created, in objectContext we searched in SSPace, the storage of physical objects (tables and columns), and then, by reflection, changed the metadata name to the name of the "incorrect" column name.

I know this is far to be the right way, but this is the only one I found. We created an extension method for ObjectBuilder that replaces that column name, so the keys are mapped to the correct column.

0
source

Source: https://habr.com/ru/post/1333823/


All Articles