ADO Entity Framework创建不必要的实体密钥 [英] ADO Entity Framework creating unwanted Entity Key

查看:80
本文介绍了ADO Entity Framework创建不必要的实体密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用无法更改的数据库中的表(使用链接服务器). 因此,我的架构的一部分是这些表的视图,并且我无法在数据库中创建FK.

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.

当我要在ADO.NET实体框架中创建关联时,我遇到了问题,因为来自外部DB的表的第二列上都有索引,并且EF正在为其创建实体键(这是名称记录的描述-我认为他们只是想加快记录的顺序.

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).

当我从EF实体中的该列上取下Entity Key时,它抱怨我需要它,因为基础表上有一个键. 如果我将其保留,则无法将其映射到EF的表映射中的任何内容.

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?

推荐答案

您将必须编辑XML并从键中删除该列.找到< EntityType> < edmx:StorageModels>中的标记部分(SSDL内容).删除任何< PropertyRef>在< Key>中这实际上不是主键的一部分.

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.

执行此操作后,可以将设计器中相应标量属性上的实体键"设置为false,EF不会发疯.您也将不再被要求在关联中映射此列.

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.

这篇关于ADO Entity Framework创建不必要的实体密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆