1
I’m trying to make a 1-to-1 relationship. Apparently it would be something simple but my system is getting lost in this relationship;
It doesn’t make a mistake, but the relationship is wrong:
Model:
public class CieloRecorrencia
 {
       [Key]
       public int CieloRecorrenciaId { get; set; }
       [ForeignKey("CieloTokenId")]
       public int CieloTokenId { get; set; }
       public virtual CieloToken CieloToken { get; set; }
}
    public class CieloToken
    {
        [Key]
        public int CieloTokenId { get; set; }
        public virtual CieloRecorrencia CieloRecorrencia { get; set; }
    }
I tried in the CieloRecorrencia place:
[ForeignKey("CieloToken")]
public int CieloTokenId { get; set; }
tried with Fluent API
    modelBuilder.Entity<CieloRecorrencia>()
      .HasOptional(s => s.CieloToken) // Mark Address property optional in Student entity
      .WithRequired(ad => ad.CieloRecorrencia);
What happens: he makes the reference to
CieloToken.CieloTokenId = CieloRecorrencia.CieloRecorrenciaId
and the right thing would be:
CieloToken.CieloTokenId = CieloRecorrencia.CieloTokenId
						
Recurrence can have 0 or 1 Tokens, that’s it?
– Leonel Sanches da Silva
that... but in practice will always have...1-1
– Dorathoto
Actually in practice one has to exist before the other. I believe it is recurrence. So I will answer based on this.
– Leonel Sanches da Silva
you are right the logic would be to put the Recursion id in the token, since it is generated later, I will change my model...
– Dorathoto
The principle is the same as it is in the answer. I think there is not much secret.
– Leonel Sanches da Silva