3

I need to use tables from a DB which I cannot alter (using linked server). So part of my schema is a view on these table and I cannot create an FK in my DB.

When I come to creating the association in ADO.NET Entity Framework I am getting problems because a second column on the table from the external DB has an index on it and the EF is creating an Entity Key for it (it's the name descr of the record - I think they just wanted to speed the ordering on it).

When I take the Entity Key off this column in the EF entity it complains that I need it because the underlying table has a key on it. If I leave it in I cannot map it onto anything in the table mapping of EF.

Does anyone know what I should do please?

stan4th
  • 33
  • 1
  • 5

1 Answers1

4

You will have to edit the XML and remove the column from the key. Find the <EntityType> tag in the <edmx:StorageModels> section (SSDL content). Delete any <PropertyRef> in the <Key> that is not actually part of the primary key.

Once you do this, you can set "Entity Key" on the corresponding scalar property in the designer to false, and EF won't get mad. You will also not be asked to map this column in associations anymore.

Michael L Perry
  • 7,327
  • 3
  • 35
  • 34