I have table called Direccion other called Cliente each one defined like this
public class Direccion
{
public short IdDireccion { get; set; }
public short IdCliente { get; set; }
public string Descripcion{ get; set; }
public virtual ICollection<Cliente> Cliente { get; set; }
}
public class Cliente
{
public short IdCliente { get; set; }
public string Descripcion { get; set; }
}
Now what I want to accomplish is a query with this output by generating an anonymous type
id <----could be idCliente or idDireccion
Descripcion <----could be the description of cliente or Direccion
idFK <---- the id of direccion related with cliente
But I start to have trouble when I navigate from Direccion to Cliente because the relation gives me the collection and I don’t know how to make the expression to handle the collection to the type that I’m expecting which is Cliente
This is my failed attempt:
var x= (from d in Direccion
where d.Activo == true select d.Cliente).Select( x => new { x.IdCliente })
var x = (from d in db.Direccion
where d.Activo == true
select d).AsQueryable().Select(xx => new { d.IdCliente });
Try the SelectMany method: