且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用VS 2015中的数据库中的EF Designer创建EF表,并且不会在生成的EF表中生成主键。

更新时间:2023-09-17 16:28:58

A2D4,

实体框架依赖于具有用于跟踪实体的密钥值的每个实体。其中一个约定该代码首先取决于它是如何暗示哪个属性是每个代码第一类中的键惯例是查找名为"ID"的
a属性或组合类名和"ID"的属性,例如" 的GroupID 跨度> 跨度>"。该属性将映射到数据库中的主键列。

Entity Framework relies on every entity having a key value that it uses for tracking entities. One of the conventions that code first depends on is how it implies which property is the key in each of the code first classes. That convention is to look for a property named "ID" or one that combines the class name and "ID", such as "GroupID". The property will map to a primary key column in the database.

>>为什么?  当我尝试使用脚手架时,我会收到错误,因为我的表没有主键。

根据您的描述,您的数据库表似乎有主键,什么操作会导致你的桌子丢失主键。

According to your description, it seems that your database tables have primary keys, what operation cause your tables lost primary keys.

祝你好运,

Cole Wu