Foreign key entity framework asp.net mvc

0

I have My Table Repair and RepairDetails and I am getting the following msg when I try to update my migration: "The introduction of the FOREIGN KEY constraint 'FK_dbo.ConsertDetalhes_dbo.Pecas_PecasId' in the 'FixDetails' table can cause cycles or multiple cascading paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION,  or modify other FOREIGN KEY constraints. Could not create restriction or index. Please refer to the above errors. "

    public class Conserto
{
    [Key]
    public int Id { get; set; }

    public DateTime DataEntrada { get; set; }
    public string NomeCliente { get; set; }
    public string NomeFuncionario { get; set; }
    public string NomePeca {get;set;}
    public string DescricaoDefeito { get; set; }
    public string DescricaoSolucao { get; set; }
    public decimal ValorMaoObra { get; set; }
    public decimal ValorTotalConserto { get; set; }
    public int PecasId { get; set; }
    public int ClienteId { get; set; }
    public int FuncionarioId { get; set; }


    [ForeignKey("PecasId")]
    public virtual Pecas Pecas { get; set; }

    [ForeignKey("ClienteId")]
    public virtual Cliente Cliente { get; set; }

    [ForeignKey("FuncionarioId")]
    public virtual Funcionario Funcionario { get; set; }

}

ConserDetails

    public class ConsertoDetalhes
{
    [Key]
    public int Id { get; set; }

    public int ConsertoId { get; set; }
    public int PecasId { get; set; }
    public decimal Total { get; set; }


    [ForeignKey("ConsertoId")]
    public virtual Conserto  Conserto { get; set; }

    [ForeignKey("PecasId")]
    public virtual Pecas Pecas { get; set; }
}
    
asked by anonymous 02.02.2018 / 16:38

1 answer

1

You are putting ForeignKey "PecasId" in the two classes (which are already related) so the migration is complaining about circular reference, remove one of the classes preferentially from the Repair class.

    
02.02.2018 / 16:51