Pre-loading data, converting to DTOs

Posts   
 
    
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 02-Nov-2017 22:48:30   

I am using LLBLGEN Pro with Entity Framework Core via C#. I would like to know

I'm considering looking at using Derived Models, but I have some queries.

1: If I create a DM, how (in C#) do I generate it from the database?

2: Will that data fetching process be optimised in some way, or will it involve multiple select statements?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Nov-2017 07:09:00   

mrpmorris wrote:

1: If I create a DM, how (in C#) do I generate it from the database?

The generation process produces two projects: one is your derived model (dto) per-se. The other one is a persistence project. This second one referenced the derived model project and has methods to project an entity into a DTO. Those projections are Linq projections you could use in your fetch routines.

mrpmorris wrote:

2: Will that data fetching process be optimised in some way, or will it involve multiple select statements?

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).

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Nov-2017 08:51:30   

EF converts the references in the projection to joins I think, and projects the whole set to a graph. No need to define include statements. See: https://www.llblgen.com/Documentation/5.3/Derived%20Models/dto_ef.htm

Frans Bouma | Lead developer LLBLGen Pro
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 03-Nov-2017 09:55:42   

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?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Nov-2017 18:48:31   

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)

Frans Bouma | Lead developer LLBLGen Pro