ADO 实体框架创建不需要的实体键
我需要使用无法更改的数据库中的表(使用链接服务器)。 因此,我的架构的一部分是这些表的视图,我无法在数据库中创建 FK。
当我在 ADO.NET 实体框架中创建关联时,我遇到了问题,因为外部数据库表上的第二列有一个索引,并且 EF 正在为其创建一个实体键(它是记录 - 我认为他们只是想加快订购速度)。
当我从 EF 实体中的此列中取出实体键时,它抱怨我需要它,因为基础表上有一个键。 如果我将其保留,我将无法将其映射到 EF 表映射中的任何内容。
请问有人知道我应该做什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须编辑 XML 并从键中删除该列。 找到中的标记 部分(SSDL 内容)。 删除任何在<键>中 这实际上并不是主键的一部分。
完成此操作后,您可以将设计器中相应标量属性上的“Entity Key”设置为 false,EF 就不会生气。 您也不会再被要求在关联中映射此列。
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.