表/视图没有定义主键 [英] The table/view does not have a primary key defined

查看:172
本文介绍了表/视图没有定义主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



将数据源添加到我的项目后,我保存了我的项目,以查看是否一切都很好,直到我做了。



但是我有一个11个警告/信息消息,说明:



表/视图'MyDataBase .TableName'没有定义主键。关键已被推断,定义被创建为只读表/视图。



我有14个表,其中4个表有自己的主键和其他表使用外键相互引用



这是什么问题?
请帮助

解决方案

EF中的每个实体必须是唯一可识别的。 EF使用数据库主键来定义实体密钥。虽然有可能在没有主键的情况下工作,但绝对不推荐,因为它会导致许多问题。核心问题直接在错误中提到 - 如果表没有主键,EF将其标记为只读,因为它不能确定它可以唯一标识要更新的记录。


I am trying to use the Databinding with WPF and Entity Framework.

After adding the data-source to my project, I saved my project in order to see whether everything is fine till what I have done.

but I have a 11 warn/info messages stating :

The table/view 'MyDataBase.TableName' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.

I have 14 Tables where 4 tables has their own primary keys and others tables are referred to each other using foreign keys

What is this issue all about? Kindly help

解决方案

Every entity in EF must be uniquely identifiable. EF uses database primary keys to define entity keys. While it is possible to work without primary keys to some extend it is definitively not recommended because it leads to many issues. The core issue is mentioned directly in the error - if the table doesn't have primary key, EF marks it as read only because it is not sure that it can uniquely identify record to be updated.

这篇关于表/视图没有定义主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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