Alan
Alan

Reputation: 466

EF CTP5 Map primary key with different column name

Property has a fluent method called HasColumnName. HasKey is missing that. In CTP4 it was possible to specify different column names through MapSingleType, but if I try to use Map (which replaced MapSingleType), it doesn't work. Any ideas?

Upvotes: 4

Views: 1520

Answers (2)

Kralizek
Kralizek

Reputation: 2063

Does this not work?

modelBuilder.Entity<Institutes.Institute>()
    .HasKey(e => e.Id)
    .ToTable("Institutes", "core");

modelBuilder.Entity<Institutes.Institute>().Property(e => e.Id)
    .HasColumnName("InstituteID");

Upvotes: 2

Mathieu H&#233;tu
Mathieu H&#233;tu

Reputation: 159

It seems that the API of CTP5 doesn't offer such possibility. What we succeed to do, is to let the ModelBuilder build its MetaDataWorkspace with the wrong key.

Then, once it is built, in the objectContext, we searched in the SSPace , the storage of Physical entities (tables and columns), then, by reflection, changed the name of the metadataproperty of the 'wrong' column name.

I know, this is far to be the right way, but it is the only one I found. We made an extension method to the ObjectBuilder, that replaces such column name, so the keys map to the correct column.

Upvotes: 0

Related Questions