流利的nhibernate HasMany Mapping

时间:2013-07-29 16:01:32

标签: c# fluent-nhibernate

我有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

请帮助......

0 个答案:

没有答案