Generally, the relationship is done through Foreign Keys information (the Foreign Keys ).
By annotation with attributes, it would look like this in Equipamento
:
public class Equipamento
{
[Key]
public int EquipamentoID { get; set; }
public string Nome { get; set; }
public string Sigla { get; set; }
// Conforme comentário do AP, essa propriedade não pode existir, ou o EF se perde.
//public virtual Databook databook { get; set; }
}
Note the use of virtual
. It is especially recommended when using the Entity Framework with configuration of use of proxies classes. Here, the property of type Databook
becomes just a navigation property.
A navigation property only signals to the Entitu Framework that a related record can be found in the indicated entity. In this case, we are indicating that a Equipamento
can (or does not) have a Databook
.
And thus in Databook
:
public class Databook
{
[Key]
public int DatabookID { get; set; }
[ForeignKey("equipamento")]
public int EquipamentoID { get; set; }
public virtual Equipamento equipamento { get; set; }
// ou assim:
// sendo esse caso o necessário para quando se trata de entidades
// com chaves compostas.
//
//[Key]
//public int EquipamentoID { get; set; }
//[ForeignKey("EequipamentoId")]
//public virtual Equipamento equipamento { get; set; }
public string Indentificacao { get; set; }
}