Modeling Error Asp.net Code First

Asked

Viewed 32 times

0

I’m having an error in making an Migration... First I’ll say what I want, so you can understand, there’s inconsistency, but I’ve tried a lot and I couldn’t solve it.

What I mean by this modeling is that:

  1. A Sketch has several Images
  2. That a report has a sketch
  3. Croqui has a virtual report because he can access the Id laudo through the sketch itself(at least that’s how I think it works)

Models:

public class Croqui
{


    [Key]
    public int CroquId { get; set; }

    [ ForeignKey("Laudo")]
    public int LaudoId { get; set; }

    public virtual Laudo Laudo { get; set; }
   public virtual ICollection<Imagem> Imagens { get; set; }
}

Imagery

 public class Imagem
{
    public int ImagemId { get; set; }
    public byte[] Image { get; set; }
    public String ImagemTipo { get; set; }

    public int CroquiId { get; set; }
    public   virtual Croqui croqui { get; set; }
}

Reports

 public class Laudo
{
    [Key]
    public int LaudoId { get; set; }


    [Display(Name = ("Ocupante"))]
    public String Ocupante { get; set; }
    [Display(Name = ("Ocupante ID"))]
    public String IdOcupante { get; set; }
    [Display(Name = ("Contato"))]
    public String ContatoOcupante { get; set; }

    [Display(Name = ("UF"))]
    public String Estado { get; set; }
    [Display(Name = ("Município"))]
    public String Municipio { get; set; }
    [Display(Name = ("Nº do Relatório"))]
    public String NumeroRelatorio { get; set; }
    public ICollection<Laudo> Laudos { get; set; }



    public  Croqui Croqui { get; set; }

Woe to error:

One or more validation errors Were Detected During model Generation: Croqui_laudo_source: Multiplicity is not Valid in Role >'Croqui_laudo_source' in Relationship 'Croqui_laudo'. Because the Dependent >Role properties are not the key properties, the upper bound of the >multiplicity of the Dependent Role must be '*'.

Thanks for your help.

1 answer

0


Models:

public class Croqui
  {
    [Key]
    public int CroquId { get; set; }


    public int LaudoId { get; set; }

    [ForeignKey("LaudoId")]
    [InverseProperty("Croquis")]
    public virtual Laudo Laudo { get; set; }


    public virtual ICollection<Imagem> Imagens { get; set; }

   }

Imagery

public class Imagem
{
    public int ImagemId { get; set; }
    public byte[] Image { get; set; }
    public String ImagemTipo { get; set; }

    public int CroquiId { get; set; }

    [ForeignKey("CroquiId")]
    [InverseProperty("Imagens")]
    public virtual Croqui croqui { get; set; }
}

Reports

According to the structure of your model in class Laudo we have a loop

public class Laudo
{
    [Key]
    public int LaudoId { get; set; }


    [Display(Name = ("Ocupante"))]
    public String Ocupante { get; set; }
    [Display(Name = ("Ocupante ID"))]
    public String IdOcupante { get; set; }
    [Display(Name = ("Contato"))]
    public String ContatoOcupante { get; set; }

    [Display(Name = ("UF"))]
    public String Estado { get; set; }
    [Display(Name = ("Município"))]
    public String Municipio { get; set; }
    [Display(Name = ("Nº do Relatório"))]
    public String NumeroRelatorio { get; set; }


     public ICollection<Croqui> Croquis { get; set; }

     public int LaudoIdSegundo { get; set; }

    [ForeignKey("LaudoIdSegundo")]
    [InverseProperty("Laudos")]
    public virtual Laudo Laudo { get; set; }

    public ICollection<Laudo> Laudos { get; set; }


}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.