1
I’m trying to create a relationship OneToOne
with EF6. In my scheme I have a User class and a Plan and the relationship would be 1 User has 1 Plan, however, this relationship is done when the User pays the Plan that then do the relationship.
I used the HasOptional<Plano>(u => u.plano)
to do the mapping on the User side, except the information in the database usually with the relationship, the problem is that when I do a search the Plan does not return together with the User and I do not know why it happens.
How to solve this ?
public class Usuario
{
public long id { get; set; }
public Plano plano { get; set; }
}
public class Plano
{
public int id { get; set; }
}
Mapping:
public class UsuarioMap : EntityTypeConfiguration<Usuario>
{
public UsuarioMap()
{
this.ToTable("Usuarios");
this.HasKey<long>(u => u.id);
this.HasOptional<Plano>(u => u.plano);
}
}
In the code below, the property Plano
is void.
Usuario usuario = context.usuarios.Where(u => u.id == usuarioSession.id).FirstOrDefault();
instead of
Include(x => x.plano)
I used theInclude("Plano")
and it worked. Thank you.– FernandoPaiva