Composite key mapping Entity framework

Asked

Viewed 275 times

0

Good afternoon,

How do I map composite key in my entities, in case 1 entity calls document and its PK is by the property ID and WEBID, and it does FK with the User as I would in that case?

Document

    public class Documento : IAggregate
    {
        [Key]
        [Column(Order = 1)]
        public int Id { get; set; }
        [Key]
        [Column(Order = 2)]
        public int WebId{ get; set; }
        public int UsuarioId { get; set; }
        public string Situacao { get; set; }
        public string Numero { get; set; }
        public string Enviadoar { get; set; }
        public DateTime DataCriacao { get; set; }
        public virtual Usuario Usuario { get; set; }
}

User:

public class Usuario : IAggregate
    {
        [Key]
        public int UsuarioId { get; set; }
        public string CodigoUsuario { get; set; }
        [Key]
        public int WebId{ get; set; }

        public string Codigo { get; set; }

        public int NumeracaoAtual { get; set; }

        public DateTime Ano { get; set; }

        public virtual ICollection<Documento> Documentos { get; set; }
}
  • The question is the same, my entity is in the same way but the error persists so I posted here, the error that occurs is: Unable to determine Composite Primary key Ordering for type 'Teste.domain.Model.Documento'. Use the Columnattribute (see http://go.microsoft.com/fwlink/?Linkid=386388) or the Haskey method (see http://go.microsoft.com/fwlink/?Linkid=386387) to specify an order for Composite Primary Keys.

No answers

Browser other questions tagged

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