1

我有 4 节课:

class Group
{
   int64 id;
   String name;
   GroupMembershipCollection members ;
}

class User
{
 int64 id;
 String name;
 GroupMembershipCollection groups;
}

class Role
{
 int64 id;
 String name;
}

class GroupMembership
{
  User User;
  Group Group;
 Role Role;
}

class GroupMembershipCollection : ObjectCollection<GroupMembership>
{}

我的映射如下:

UserMap
{
    //other maps 
  this.HasMany<GroupMembershipCollection, GroupMembership>(p => p.Groups, cfg => cfg.Cascade.AllDeleteOrphan());    }

GroupMap
{
    //other maps
   HasMany<GroupMembershipCollection, GroupMembership>(g => g.Members, cfg => cfg.Cascade.AllDeleteOrphan());
}

GroupMemberShipMap
{
     References(x => x.User).Cascade.None();
 References(x => x.Group).Cascade.None();
 References(x => x.Role).Cascade.None();
 }

当我尝试将成员添加到组时,它给了我以下错误:

INSERT 语句与 FOREIGN KEY 约束“FK_GroupMemberships_UserID”冲突。在表 dbo.Users 上

当我尝试将组添加到成员时,我得到了这个:

INSERT 语句与 FOREIGN KEY 约束“FK_GroupMemberships_GroupID”冲突。在表 dbo.Groups 上

请帮忙...

4

0 回答 0