0
I’m trying to make the relationship between my Cliente
and the CieloToken
, tried with Fluent API
and Data Annotation
, I mixed them together and it didn’t work.
In fact it executes, but even if the Cliente
did not have CieloToken
he ends up bringing some data even if it’s from another client!
Model:
public class Cliente
{
[Key]
[Column("intid")]
[ForeignKey("ConfigCliente")]
[Display(Name = "IDC")]
public int ClienteId { get; set; }
public virtual ICollection<Boleto> Boletos { get; set; }
public virtual ConfigCliente ConfigCliente { get; set; }
public virtual CieloToken CieloToken { get; set; }
}
//No caso acima quero trazer o CieloToken lembrando que ele não é obrigatório, alguns clientes não tem.
public class CieloToken
{
[Key]
[Column("int_ID")]
public int CieloTokenId { get; set; }
[Column("int_IDC")]
[Required] //tentativa
[ForeignKey("Cliente")] //tentativa
public int ClienteId { get; set; }
public virtual ICollection<CieloTransacao> cieloTransacao { get; set; }
public virtual Cliente Cliente { get; set; }
}
//Aqui em CieloToken, caso exista sempre terá um Cliente
When I do
var cliente = db.Clientes.Find(3);
It returns a Cielotoken, even if this client(3) does not have!
Cielotoken has a customer, not always a Customer has a Cielotoken.
– Dorathoto
So it seems right to me. Have you tried this code?
– Vinicius Grund