New Posts New Posts RSS Feed: Include with Inheritance
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Include with Inheritance

 Post Reply Post Reply
Author
rhaney View Drop Down
Newbie
Newbie


Joined: 06-Jul-2010
Location: Orange, CA
Posts: 12
Post Options Post Options   Quote rhaney Quote  Post ReplyReply Direct Link To This Post Topic: Include with Inheritance
    Posted: 27-Jul-2010 at 3:29pm

Let's say I have an e-commerce site, with different types of products.  For instance, books and dvds.  I create a model with the following entities:

Catalog
Product
Book (of type Product)
Dvd (of type Product)
Author
Director
 
Catalog has Products (Books/Dvds)
Book has a collection of Authors
Dvd has a single Director
 
How would I eager load information about Books and Dvds in the same query?
 
I tried the following, but get an exception:
var query = from c in em.Catalogs.AddIncludePaths("Products, "Products.Authors", "Products.Director");
 
I was thinking a Silverlight like syntax might be nice:
var query = from c in em.Catalogs.AddIncludePaths("Products, "Products.(Book.Authors)", "Products.(Dvd.Director)");
 
Does such a syntax exist?
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jul-2010 at 5:42pm
Good question.  The .Include functionality in LINQ (which we mirror) does not support this, but you can do this by using a projection in DevForce.  I believe the query below should accomplish what you were trying to do.  It returns an anonymous type, but all of the various components will still be brought into the DevForce cache.
 
var results = em.Catalogs.Select(c => new {
  Catalog = c,
  Products = c.Products,
  Authors = c.Products.OfType<Book>().Select(b => b.Author),
  Directors = c.Products.OfType<Dvd>().Select(d => d.Director)
 }).Execute();
 


Edited by ting - 27-Jul-2010 at 5:42pm
Back to Top
rhaney View Drop Down
Newbie
Newbie


Joined: 06-Jul-2010
Location: Orange, CA
Posts: 12
Post Options Post Options   Quote rhaney Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jul-2010 at 5:48pm
That's a great suggestion :-)....in fact, I like it a lot better than the Include statements....(strongly typed, deep eager loading...)
 
Will try it out....thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down