WAQS Querying: IncludeFor

7 reasons to use WAQS

WAQS documentation


Imagine that you want to calculate a calculated property in memory or you need to execute a service method.

As I previously explain, I don’t want to have lazy loading. So it’s very important to load all navigation properties need to execute the expected code.

So, for this scenario, WAQS introduces the IncludeFor method.


Analyzing specification code, WAQS deduces the dependences of each method defined in the specifications.

Based on it, WAQS can add the different includes.


So for example, imagine that we use the first MakeInvoice method I defined here:

public static Invoice MakeInvoice(this Order o)
     Invoice invoice = new Invoice { OrderId = o.Id, CustomerId = o.CustomerId, Total = GetTotal(o) };
     if (o.Customer != null)
         invoice.CustomerCompanyName = o.Customer.CompanyName;
         invoice.CustomerContactName = o.Customer.ContactName;
     foreach (var od in o.OrderDetails)
new InvoiceDetail { OrderDetailId = od.Id, Quantity = od.Quantity, UnitPrice = od.UnitPrice, Discount = od.Discount, Amount = GetAmount(od) });
     return invoice; }


Now, we want to get orders and we want to be able to make their invoice. We can use this query:

await _context.Orders.AsAsyncQueryable().IncludeForMakeInvoice().Execute()


With this IncludeForMakeInvoice generated method:

public static IAsyncQueryable<Order> IncludeForMakeInvoice(this IAsyncQueryable<Order> query)
     bool done = false;
     IncludeForMakeInvoiceCustomQueryable(ref query, ref done);
     if (done)
       return query;
     query = query.IncludeCustomer().IncludeOrderDetailsWithExpression (e2 => e2.WithAmount()).WithTotal();      return query; } static partial void IncludeForMakeInvoiceCustomQueryable(ref IAsyncQueryable<Order> query, ref bool done);
This entry was posted in 12253, 16868. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *