我有以下实体:项目、项目映射和用户,它是多对多这里是映射:
public ProjectMembershipMapping()
{
Property(pm => pm.IsAccepted, prop => prop.NotNullable(true));
Property(pm => pm.Permission, prop => prop.NotNullable(true));
ManyToOne(pm => pm.Member, mapping =>
{
mapping.Lazy(LazyRelation.NoLazy);
mapping.Cascade(Cascade.All);
});
ManyToOne(pm => pm.Project, mapping =>
{
mapping.Lazy(LazyRelation.NoLazy);
mapping.Cascade(Cascade.All);
});
ComposedId(pm =>
{
pm.ManyToOne(prop => prop.Member);
pm.ManyToOne(prop => prop.Project);
});
}
public ProjectMapping()
{
Set(proj => proj.Members,
mapping =>
{
mapping.Lazy(CollectionLazy.NoLazy);
mapping.Inverse(false);
mapping.Cascade(Cascade.All);
mapping.Table("ProjectMembership");
mapping.Key(k => k.Column("Project"));
},
action => action.OneToMany()
);
}
public class DevcoopUserMapping : ClassMapping<DevcoopUser>
{
Bag(user => user.ProjectMemberships,
mapping =>
{
mapping.Lazy(CollectionLazy.NoLazy);
mapping.Inverse(false);
mapping.Cascade(Cascade.All);
mapping.Table("ProjectMembership");
mapping.Key(k => k.Column("Member"));
},
action => action.OneToMany());
}
用户可以是许多项目的成员。现在假设我要取消他对项目的订阅。只需通过 ISession 对象删除 ProjectMembership 对象就会抛出我:
deleted object would be re-saved by cascade (remove deleted object from associations)[devcoop.Daos.ProjectMembership#devcoop.Daos.ProjectMembership]
另一方面,当我第一次尝试从 Project 和 User 中删除这个 ProjectMembership 实例时(我按照建议从关联中删除它),我得到了异常:
could not delete collection: [devcoop.Daos.Project.Members#1][SQL: UPDATE ProjectMembership SET Project = null WHERE Project = @p0]
任何人都可以帮忙吗?据说我在映射周围搞砸了一些东西,但我不知道这是什么。