ADO Entity Framework creating an unwanted Entity key

I need to use tables from a database that I cannot modify (using a linked server). So part of my schema is the view on this table, and I cannot create an FK in my database.

When I come to the creation of an association in the Entity Framework ADO.NET, I have problems because the second column of the table from the external database has an index on it, and EF creates an Entity key for it (this is the name descr of the record - I think they just wanted to speed things up on it).

When I get the Entity Key from this column in the EF element, it complains that I need it because there is a key in the base table. If I leave it, I cannot match it with anything in the EF mapping table.

Does anyone know what I should do, please?

+3
source share
1 answer

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

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

+4
source

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


All Articles