Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> A Where clause on a prefetchpath
 

Pages: 1
LLBLGen Pro Runtime Framework
A Where clause on a prefetchpath
Page:1/1 

  Print all messages in this thread  
Poster Message
LarsC
User



Location:

Joined on:
20-Aug-2019 09:38:31
Posted:
2 posts
# Posted on: 20-Aug-2019 09:54:16.  
(LLBLGen Pro V5.5, adapter. I guess this problem is not related to database type etc. I can provide those details if needed.)

With a standard schema where a Customer can have multiple Orders.

How do I retrieve all Customers of a region which has at least one Order with Status "Pending".

This was the existing code which retrieves all Customers including all Orders for a certain region with paging.

Code:
var qf = new QueryFactory();

var q = qf.Customer
    .Where(CustomerFields.Region.Equal("Europe"))
    .WithPath(CustomerEntity.PrefetchPathOrders
        .WithOrdering(OrderFields.Nr.Ascending()))
    .OrderBy(CustomerFields.ID.Descending())
    .Page(pageNr, customersPerPage);



Tried adding this filter on PrefetchPathOrders
Code:
.WithFilter(OrderFields.Status.Equal("Pending"))


But this will only filter all orders and the result will include Customers which had no pending orders.

Do I have to use joins of some sort?

I'd like to think that I, instead of a filter, could add
Code:
.Where(OrderFields.Status.Equal("Pending"))

Or something similar.
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14529 posts
# Posted on: 20-Aug-2019 19:53:24.  
Yes you should use Joins to filter on the main entity you are fetching.
PrefetchPaths are there to fetch related entities to filter the main entity list.

Example:
Code:
var query = qf.Order
     .From(QueryTarget.InnerJoin(qf.OrderDetail)
    .On(OrderFields.OrderId == OrderDetailFields.OrderId))
    .From(QueryTarget.InnerJoin(qf.Product)
    .On(ProductFields.ProductId == OrderDetailFields.ProductId)).Where(ProductFields.CategoryId == 2)



  Top
LarsC
User



Location:

Joined on:
20-Aug-2019 09:38:31
Posted:
2 posts
# Posted on: 26-Aug-2019 12:43:10.  
Walaa wrote:
Yes you should use Joins to filter on the main entity you are fetching.
PrefetchPaths are there to fetch related entities to filter the main entity list.

Example:
Code:
var query = qf.Order
     .From(QueryTarget.InnerJoin(qf.OrderDetail)
    .On(OrderFields.OrderId == OrderDetailFields.OrderId))
    .From(QueryTarget.InnerJoin(qf.Product)
    .On(ProductFields.ProductId == OrderDetailFields.ProductId)).Where(ProductFields.CategoryId == 2)



Thanks. It helped!
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.