New Posts New Posts RSS Feed: Filter on entities futher away on the business object path
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Filter on entities futher away on the business object path

 Post Reply Post Reply
Author
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Topic: Filter on entities futher away on the business object path
    Posted: 29-Oct-2009 at 12:00am
I cannot define an entity query that filters entities that are futher away than "nextdoor" to the root entity.
 
Please consider this:
 
var query = manager.Orders
.Include("Customer")
.Include("OrderDetails")
.Include("OrderDetails.Product")
.Where(a => a.OrderDetails.Product.ProductName == "Duff Beer");
The properties of the Product entity are not exposed to filter on. ProductName is not exposed via intellisense.
 
Do you know of another method to achieve this instead ?
 
My real world need has yet another entity on the object graph to navigate to as well.  At this stage I am considering the creation of a sql view (though not preferred).
 
Thanks kindly
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 30-Oct-2009 at 6:52am
Bigfish:

LINQ wants the subject in the Where clause to be a single property of the object currently being examined (an Order, in your query). It doesn't know how to resolve the expression "a.OrderDetails.Product", because that isn't a single property of Order.

You need to rewrite your query as follows:

var query = manager.OrderDetails
  .Where(od => od.Product.ProductName == "Duff Beer")
  .Select(od => od.Order)
    .Include("Customer")
    .Include("OrderDetails")
    .Include("OrderDetails.Product");

First you obtain the set of OrderDetails that meet your condition; then from that set, project the related Orders. Note that the Includes are specified in relation to the projected type (Order), not the type initially referenced in the query (OrderDetail).

Back to Top
bigfish View Drop Down
Newbie
Newbie


Joined: 20-Mar-2009
Location: Australia
Posts: 36
Post Options Post Options   Quote bigfish Quote  Post ReplyReply Direct Link To This Post Posted: 31-Oct-2009 at 1:03am
Thanks heaps Greg, much appreciated.  That helps a lot.
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2009 at 11:28am
Quite welcome, bigfish.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down