Related entities in the projection on a database query

Posts   
 
    
Sjss
User
Posts: 1
Joined: 10-Apr-2020
# Posted on: 10-Apr-2020 18:23:10   

Hello, I’m just using LLBL for ASP.net core with adapter mode v5.6 I have an issue with using DTO classes, In the projection on a database query, the return the dto filled with the related entities even without adding a path in the query

For example for customer and customerDetail


var metaData = new LinqMetaData(adapter);
    var q = (from c in metaData.Customer
             select c)
            .ProjectToCustomer();
    resultsDTO = q.ToList();

the resultsDTO contains customer and customerDetail for each customer.

My questions are

Why this behavior by default ? How I can switch on/off to allow/prevent related entities without doing in memory projection?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Apr-2020 08:18:48   

The .ProjectToCustomer() is a helper method that allows you to fill the DTO you built. If you go to definition to that method you can see the projection's tree construction, which is generated by a template. If you want a different behavior you could write your own .ProjectToCustomerSimple() method that removes the child elements, or you could simply not call any method, just do a.ToList() to fill with entities, then you construct the DTO yourself based on the result.

You can read more about DTO projections here in the documentation.

David Elizondo | LLBLGen Support Team