1

我有两个实体:

public class Report : SimpleEntity
{
     public virtual ICollection<BaseFrequency> Frequencies
    {
        get
        {
            return _requencies ?? (_requencies = new HashSet<BaseFrequency>());
        }

        set
        {
            _requencies = value;
        }
    }
}

public class CustomReport : SimpleEntity
{
   public virtual string Name {get; set;}

   public Report Report { get; set; } 
}

映射:

internal class BaseFrequency: EntityMappingBase<BaseFrequency>
    {
        public BaseFrequency()
        {
            Property(x => x.Name).HasMaxLength(250).IsRequired(); 
        }
    }

internal class MyReportMapping : EntityMappingBase<MyReport>
{
    public MyReportMapping()
    {
        HasMany(x => x.Frequencies).WithOptional(x => x.Report).HasForeignKey(x => x.ReportId).WillCascadeOnDelete(true);         
    }
}

当我删除报告时,我得到“

DELETE 语句与 REFERENCE 约束 \"Report_Frequencies\" 冲突。数据库 \"SamAssist\"、表 \"dbo.BaseFrequencies\"、列 'ReportId' 中发生冲突。\r\n语句已终止。"} 错误 DELETE 语句与 REFERENCE 约束 \"Report_Frequencies\" 冲突. 数据库 \"SamAssist\"、表 \"dbo.BaseFrequencies\"、列 'ReportId' 中发生冲突。\r\n语句已终止

数据库限制是在此处输入图像描述

我应该怎么做才能修复这个错误?

4

0 回答 0