Error 3002: Problem in mapping fragments | c# linq to entities

错误展示:

Error 3002: Problem in mapping fragments starting at line 1330:Potential runtime violation of table FTPRuns’s keys (FTPRuns.ID): Columns (FTPRuns.ID) are mapped to EntitySet FTPRuns’s properties (FTPRuns.ID) on the conceptual side but they do not form the EntitySet’s key properties (FTPRuns.ID, FTPRuns.LastRun).

原因分析:

Your entity model has the combination of the two properties FTPRuns.ID and FTPRuns.LastRun as entity key while your table has only the column FTPRuns.ID as primary key. So in your model you specify that the combination of FTPRuns.ID and FTPRuns.LastRun must be unique while your database has the stronger requirement that FTPRuns.ID alone must be unique.

Just exclude the property FTPRuns.LastRun from the entity key. Maybe this happened accidentally or the Entity Framework could not get primary key information from the database and had to infer the entity key. For example views have no primary key and the Entity Framework will infer the entity key as the combination of all non-nullable columns.

实体是两个属性FTPRuns.ID和FTPRuns.LastRun的复合主键,而数据库表仅仅只有一个FTPRuns.ID作为主键。所有你的实体指定两个属性的复合主键必须唯一,而数据库则要求仅仅FTPRuns.ID必须唯一。

从实体主键中排除FTPRuns.LastRun属性,这个可能是偶然发生的,或者EF不能从数据库得到主键信息,并且必须通知实体主键。例如,看那些没有主键的表,EF将通知实体以所有不为空的列作为实体主键

猜你喜欢

转载自blog.csdn.net/Vincent_yuan1991/article/details/82698477
今日推荐