Everything is in designing the domain well, before writing a line of code you have to understand how the business operates and thinks, for that we have the UML that helps us to abstract the real world, to recognize the business entities and their Attributes, based on the information you have provided, I have taken the liberty of modeling what your domain may be.
Depending on the domain, it must be a true copy in the implementation of your code and a faithful copy in your database.
Your class would be as follows according to your solution design.
Title
public class Titulo
{
public int TituloId { get; set; }
public string Nombre { get; set; }
//Siempre y cuando deseas tener una colección de controles
public virtual ICollection<Control> Controles { get; set; }
}
Buyer
public class Comprador
{
public int CompradorId { get; set; }
public string Nombre { get; set; }
//Siempre y cuando deseas tener una colección de controles
public virtual ICollection<Control> Controles { get; set; }
}
Control
namespace Dominio
{
public enum EnumEstado : int { Activo = 1, Inactivo = 2}
public class Control
{
public int ControlId { get; set; }
public int CompradorId { get; set; }
public int TituloId { get; set; }
public string Codigo { get; set; }
public DateTime Fecha { get; set; }
public EnumEstado Estado { get; set; }
//Propiedades de navegación
public virtual Comprador Comprador { get; set; }
public virtual Titulo Titulo { get; set; }
}
}
With these navigation properties you can access the other entities from Control and elaborate your queries using linq to entities.
I have created an extended Control Control class to be able to create the query since there can not be properties of the same name.
ControlExtend
public class ControlExtend
{
public string NombreComprador { get; set; }
public string NombreTitulo { get; set; }
}
Your query would be as follows, in which I use the navigation properties to access the other entities.
public List<ControlExtend> ListarControles()
{
using (MyContext context = new MyContext())
{
var result = (from item in context.Controles
select new ControlExtend()
{
NombreComprador = item.Comprador.Nombre,
NombreTitulo = item.Titulo.Nombre
}).ToList();
return result;
}
}
Greetings!