public class ReviewMap : ClassMapBase<Review>
{
public ReviewMap()
{
Table("Reviews");
List(x => x.Objectives, m =>
{
m.Table("Objectives");
m.Cascade(Cascade.All.Include(Cascade.DeleteOrphans));
m.Key(k => k.Column("ReviewId"));
m.Where("DeletionDate is null");
m.OrderBy("OrderNo");
m.Index(x => x.Column("OrderNo"));
m.Inverse(true);
}, m => m.OneToMany());
}
public class ObjectiveMap : ClassMapBase<Objective>
{
public ObjectiveMap()
{
Table("Objectives");
// Use "soft deletes" to allow us to capture results against deleted items
Where("DeletionDate is null");
SqlDelete("update Objectives set DeletionDate = getutcdate(), OrderNo = 1 where id=?");
ManyToOne(x => x.Review, m =>
{
m.Column("ReviewId");
m.NotNullable(true);
});
Property(x => x.Details, m =>
{
m.NotNullable(true);
m.Length(1000);
m.Column("Details");
});
Property("OrderNo", m =>
{
m.NotNullable(false);
});
}
}
当我尝试删除评论时,它给了我目标表中外键约束的错误。因为 ReviewId 是 Objectives 表中的外键。
你能提出什么问题吗?