ADO Entity Framework creating unwanted Entity Key

女生的网名这么多〃 提交于 2019-12-06 07:42:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/638133/ado-entity-framework-creating-unwanted-entity-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!