简体   繁体   English

在表“模型”上引入FOREIGN KEY约束“列”可能会导致循环或多个级联路径

[英]Introducing FOREIGN KEY constraint 'Column' on table 'Model' may cause cycles or multiple cascade paths

I want to make relationship but i getting this error: 我想建立关系,但出现此错误:

Introducing FOREIGN KEY constraint 'FK_dbo.MatchModels_dbo.LookingForaHomes_PropertyID' on table 'MatchModels' may cause cycles or multiple cascade paths. 在表“ MatchModels”上引入FOREIGN KEY约束“ FK_dbo.MatchModels_dbo.LookingForaHomes_PropertyID”可能会导致循环或多个级联路径。 Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. 指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。 Could not create constraint or index. 无法创建约束或索引。 See previous errors. 请参阅先前的错误。

I have two model to add property and I divide by 'PropertyType' 我有两种添加属性的模型,并且按“ PropertyType”进行划分

For example; 例如; matchModel have 2 rows; matchModel有2行;

MatchID 1 PropertyID 23 PropertyType 2.... MatchID 1 PropertyID 23 PropertyType 2 ....

MatchID 2 PropertyID 23 PropertyType 1.... MatchID 2 PropertyID 23 PropertyType 1 ....

if PropertyType value is 2, its for LookingForaHome or value is 1 it's for LookingForaMate. 如果PropertyType值为2,则它用于LookingForaHome;如果值是1,则用于LookingForaMate。 Is it true way I dont know but according to this logic I should make relationship for 我不知道这是真的吗,但根据这种逻辑,我应该为

MatchModel: PropertyID -> LookingForaMate: PropertyID MatchModel:PropertyID-> LookingForaMate:PropertyID

MatchModel: PropertyID -> LookingForaHome: PropertyID MatchModel:PropertyID-> LookingForaHome:PropertyID

How can i make relationship ? 我该如何建立关系?

public class LookingForaHome
    {
        [Key]
        public int PropertyID { get; set; }

     ...


        public DateTime InsertionDate{ get; set; }


        [Required]
        public int UserID { get; set; }


        public List<MatchModel> Match{ get; set; }
        public virtual UserModel User { get; set; }
        public virtual CityModel City { get; set; }

        //Default Values

        public LookingForaHome()
        {
            InsertionDate = DateTime.Now;
        }

    }




public class LookingForaMateModel
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Key]
    public int PropertyID { get; set; }

    ....

    [Required]
    public int UserID { get; set; }


    public DateTime InsertionDate { get; set; }

    public LookingForaMateModel()
    {
        InsertionDate = DateTime.Now;
    }

    public List<PropertyPhotoModel> PropertyPhoto { get; set; }

    public List<MatchModel> Match { get; set; }

    public virtual UserModel User { get; set; }
    public virtual CityModel City { get; set; }
}




public class MatchModel
    {
        [Key]
        public int MatchID { get; set; }

        [Required]
        public int PropertyID { get; set; }
        [Required]
        public int PropertyType { get; set; }

        [Required]
        public int UserID { get; set; }

        [Required]
        public bool IsSeen { get; set; }

        [Required]
        public DateTime InsertionDate { get; set; }

        public virtual UserModel User { get; set; }

        public virtual LookingForaMateModel LFMate { get; set; }
        public virtual LookingForaHome LFHome{ get; set; }

        public MatchModel() {
            InsertionDate = DateTime.Now;

        }
    }

Simpler changes is to use two nullable columns for each type. 更简单的更改是为每种类型使用两个可为空的列。

public class MatchModel
{
    [Key]
    public int MatchID { get; set; }

    [ForeignKey("LFMate")]
    public int? MatePropertyID { get; set; }
    [ForeignKey("LFHome")]
    public int? HomePropertyType { get; set; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ef核心2-在表&#39;Y&#39;上引入FOREIGN KEY约束&#39;X&#39;可能会导致循环或多个级联路径 - ef core 2 - Introducing FOREIGN KEY constraint 'X' on table 'Y' may cause cycles or multiple cascade paths 在表上引入外键约束可能会导致循环或多个级联路径 - Introducing Foreign key Constraint on table may cause cycles or multiple cascade paths 实体框架:在表 '' 上引入 FOREIGN KEY 约束 '' 可能会导致循环或多个级联路径 - Entity Framework: Introducing FOREIGN KEY constraint '' on table '' may cause cycles or multiple cascade paths 表&#39;UsageSummaries&#39;上的多态与引入FOREIGN KEY约束可能会导致循环或多个级联路径 - Polymorphism vs Introducing FOREIGN KEY constraint '' on table 'UsageSummaries' may cause cycles or multiple cascade paths 在表table上引入FOREIGN KEY约束键可能会导致循环或多个级联路径。 指定ON DELETE…错误 - Introducing FOREIGN KEY constraint key on table table may cause cycles or multiple cascade paths. Specify ON DELETE … Error 当不需要属性时,引入外键约束可能会导致循环或多个级联路径 - Introducing Foreign Key Constraint may cause cycles or multiple cascade paths when property is not required 错误:引入FOREIGN KEY约束可能会导致循环或多个级联路径-为什么? - Error: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths - why? SQL 错误:引入 FOREIGN KEY 约束可能会导致循环或多个级联路径。 实体框架核心 - SQL Error: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths. Entity Framework Core 引入FOREIGN KEY约束可能会导致EF Core中的循环或多个级联路径 - Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths in EF Core 避免“引入FOREIGN KEY约束可能会导致循环或多个级联路径” - Avoiding 'Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM