无法添加到edmx的视图 [英] cannot add view to the edmx

查看:149
本文介绍了无法添加到edmx的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试向edmx文件添加视图时,没有任何反应。

我使用wxl编辑器打开了edmx文件,并注意到以下错误:

When trying to add a view to the edmx file, nothing happens.
I opened the edmx file using wxl editor and I noticed the following error:


警告6013:表/视图
'CellularOrders.dbo.V_LINK'不
有一个主键定义,没有
有效的主键可以被推断。
此表/视图已被排除。对于
使用实体,您将需要
检查您的模式,添加正确的
键,并取消注释。

warning 6013: The table/view 'CellularOrders.dbo.V_LINK' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.

(重要的事情 - 我没有,并且不需要添加基于edmx的视图的表。此外,该视图仅用于对数据进行select语句)

(importent thing - I didn't and don't need to add the table which the view based on to the edmx. Moreover, the view is only for doing select statements on the data)

所以在数据库中,我更新了T_LINK表,并将其中一个反映在视图上的字段作为主键。然后,当我再次尝试将视图添加到edmx时,不会再发生任何事情。

So in the db, I updated the T_LINK table and made one of the fields that reflects on the view as primary key. And then, when I tryed again to add the view to the edmx nothing happens again.

我该如何解决?
有没有一个选项来解决这个问题,而不用做任何事情呢?
我可以添加另一个视图,以某种方式包装旧视图,但是具有固定的属性?

How can I solve this?? Is there an option to fix this without doing anything to the table? Can I add another view that will somehow wrap the old view but with fixed properties?

推荐答案

每个表或视图添加到实体模型必须有一些关键。实际上并不一定是主键。如果表没有定义的主键EF将尝试使用简单规则来推断密钥:它将使所有不可为空的非计算非二进制列并将其标记为实体密钥。如果没有这样的列存在,则不能自动添加实体,并且设计者将抛出所提到的警告。解决方法是手动添加视图,自己选择密钥,但一旦执行,您将无法使用从数据库更新更新,因为它将始终覆盖您的更改。

Each table or view added to entity model must have some key. It actually doesn't have to be primary key. If the table doesn't have the primary key defined EF will try to infer a key using simple rule: It will take all non-nullable non-computed non-binary columns and marks them as an entity key. If none such column exist the entity cannot be automatically added and the designer will throw the mentioned warning. Workaround is adding the view manually and selecting the key yourselves but once you do it you cannot use Update from database because it will always overwrite your changes.

您定义的密钥应该是唯一的,否则您可能会遇到与身份相关的其他问题地图内部使用。

Your defined key should be unique otherwise you can have some other problems related to identity map used internally.

这篇关于无法添加到edmx的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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