0

I was wondering if it was possible to select/build a multilevel object hierarchy in one single query? As I'm not sure about the terminology, I'll give an example:

Let's say we have a Product, which has one Subrange, which has one Range, which has one Provider.

I can easily build my Product POCO with its Subrange with

Db.Products.WithSubrange.Get(#id);

But could I build it with Product.Subrange.Range and Product.Subrange.Range.Provider in a single query? I've tried several ways, like:

Db.Products.With(Db.Products.Subrange.WithRange()).Get(#id);
Db.Products.With(Db.Subrange.WithRange()).Get(#id);

but I can't find it out. It would be ok to query the Range and Provider afterward (it's already amazing this way) but a single query would be nice. Explicit Joins maybe?

BTW if Sir Rendle happens to come-by, I would like to thank him for his amazing work. Simple.Data rocks!

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
IronSlug
  • 492
  • 3
  • 15

1 Answers1

0

Try chaining the 'With's

Db.Products.WithSubRange().WithRange().WithProvider().Get(#id);

Alternatively you can use

Db.Products.FindAllById(#id).WithSubRange().WithRange().WithProvider().FirstOrDefault();

Read: http://simplefx.org/simpledata/docs/pages/Retrieve/LazyVsEagerLoading.htm

The act of doing what you have described relates to the terms "Lazy Loading" and "Eager Loading".

MartinM
  • 1,736
  • 5
  • 20
  • 33
  • I recall trying it with no success already, but I might be wrong so I'll give it another shot and let you know. – IronSlug Dec 09 '14 at 14:32