1
How can I load data from multiple tables in the Entity Framework? By RAW Query
I get normal, but by the Entity Framework I’m not getting to the point.
What I need is to select the last entry that contains a specific product (I will pass the ID) ordered by the Decreasing Dataregistration (identify that is the last one) and together select the PRODUCT object I passed the ID?
Obs: I removed the Annotations and mapping to decrease the post size!
I access the entrance through my:
contexto.Entrada.Lista().Where(...).OrderByDescending(m => m.DataCadastro).FirstOrDefault();
Classes:
class Entrada {
public int Id { get; set; }
public DateTime DataCadastro { get; set; }
public virtual ICollection<ItemEntrada> Items;
}
class Produto {
public int Id { get; set; }
public string Nome { get; set; }
}
class ItemEntrada {
public int Id { get; set; }
public int EntradaId { get; set; }
public int ProdutoId { get; set; }
public virtual Produto Produto { get; set; };
public virtual Entrada Entrada { get; set; };
}
Put Apolo to your SQL that you put in your
RAW
?– Maria
I did with Join but I cannot use RAW SQL need to use Entity framework in the project.
– Apolo
Apolo, I want to see your Raw SQL that then I shoot and send by the Entity understood!
– Maria
Maria I appreciate the help, but it contains company information and process, I can not pass! The data above are invented! In the case of the query it would return the input and the!
– Apolo
Ok @Apolo, I made an answer let’s see if it’s right... !!! please test and tell me! If I see the SQL I will any
Lambda Expression
would be quieter ... but, all right we will respect the company!– Maria