【发布时间】:2014-06-09 09:25:46
【问题描述】:
我可以在设计视图中进入 EDMX 并更新关联的基数(1-、0- 等),但我想知道这样做是否可以场景。
我有这两张表,比方说:
User
-----
Id
UserProfile
-------------
Id
UserId
Stuff
单个用户可能只有一个个人资料。因此,我在UserProfile 表中的UserId 列中设置了唯一约束。此外,UserProfile.Id 被定义为引用 User.Id 的外键。
但是,在实体框架模型中,我得到以下信息:
class User
{
ICollection<UserProfile> UserProfiles { get; set; }
}
起初,UserProfile 表没有任何自己的主键,如下所示:
UserProfile
--------------
UserId
Stuff
但 EntityFramework 将其设为只读,因为它需要在您希望使其可写的每个表上都有一个主键。所以,我也在UserProfile 表中添加了一个Id 列。
更新
我尝试在设计器的 EDMX 中设置 User 表和 UserProfile 表之间关联的多重性/基数。但是,我收到此错误,建议我应该将其恢复为原来的状态,即一对多关系。
Running transformation: Multiplicity is not valid in Role 'UserBasicProfile'
in relationship 'FK_UserBasicProfile_User'. Because the Dependent Role
properties are not the key properties, the upper bound of the multiplicity
of the Dependent Role must be *.
【问题讨论】:
标签: entity-framework entity-framework-5