简体   繁体   English

带有实体框架键的错误消息

[英]Error message with Entity Framework keys

I'm running EF4.3, database first. 我正在运行EF4.3,首先是数据库。

My primary key for users is UserId which I use to relate to all other associated tables. 我的用户主键是UserId,它用于与所有其他关联的表相关。

I have 3 types of users all of which have unique values so they are stored in their own tables. 我有3种类型的用户,它们都有唯一的值,因此它们存储在自己的表中。 They are, Contributors, Members and Administrators. 他们是贡献者,成员和管理员。

A further constraint is placed on these tables using UserId and UserRoleId in the user table and UserId and a fixed UserRoleId in the subordinate tables. 使用用户表中的UserId和UserRoleId以及从属表中的UserId和固定的UserRoleId,对这些表施加了进一步的约束。 For instance, the Members table will have a computed value of '3' which is the UserRoleId of a member. 例如,Members表将具有一个计算值“ 3”,它是成员的UserRoleId。 This ensures that a user can only exist in 1 of the subscriber tables at any one time. 这样可以确保用户一次只能存在于一个订户表中。

EF throws an error in the edmx build because UserRoleId is not part of the primary key of the Users table. EF在edmx构建中引发错误,因为UserRoleId不属于Users表主键。 Everything seems to work ok but just wondered if there is either something I'm doing wrong or there is anything I can do to circumvent the errors. 一切似乎都正常,但只是想知道是我做错了什么,还是可以做些什么来规避错误。

您需要更改UserRoleId的名称,因为EF认为这是PR密钥,或者您希望UserRoleId成为属性顶部[Key]的一部分,请使用UserRoleId。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM