mrpmorris wrote:
daelmo wrote:
Those projections are Linq projections you could use in your fetch routines.
The projection is emitted as better as can be. However, at the end of the day, the queries are built by your EntityFramework, so it depends on that (how good it's to construct complex queries in efficient sql statements, the EF version, etc).
Does that mean you use the .Include() extension in EntityFramework?
No, the projections use nested projections which result in joins in the end query.
private static System.Linq.Expressions.Expression<Func<NWEFCore2.EntityClasses.Customer, NWEFCore2.Dtos.DtoClasses.CustomerOrder>> CreateProjectionFunc()
{
return p__0 => new NWEFCore2.Dtos.DtoClasses.CustomerOrder()
{
CompanyName = p__0.CompanyName,
CustomerId = p__0.CustomerId,
Orders = p__0.Orders.Select(p__1 => new NWEFCore2.Dtos.DtoClasses.CustomerOrderTypes.Order()
{
Employee = new NWEFCore2.Dtos.DtoClasses.CustomerOrderTypes.OrderTypes.Employee()
{
FirstName = p__1.Employee.FirstName,
LastName = p__1.Employee.LastName,
},
OrderDate = p__1.OrderDate,
OrderId = p__1.OrderId,
}).ToList(),
};
}
Here a set of DTOs is fetched over customer, order and employee of Northwind. One query, it will join things together (in EFcore 2, in 1 it would sometimes run in memory due to the flakyness of their linq provider)