google-code-export / dataobjectsdotnet

Automatically exported from code.google.com/p/dataobjectsdotnet
0 stars 0 forks source link

Simplified .Prefetch API #710

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As it was noted, it would be much more convenient if we could use this API:

var owner = Query.All<Owner>()
  .Where(o => o.UserID == 512)
  .Prefetch(o => o.Beneficiary)
  .Prefetch(o => o.Document)
  .Prefetch(o => o.Document.Lookup)
  .Prefetch(o => o.Document.BaseInsurance)
  .Prefetch(o => o.Product)
  .Prefetch(o => o.Property)
  .Prefetch(o => o.Event)
  .Prefetch(o => o.SecurityQuestion)
  .Prefetch(o => o.Lookup)
  .Prefetch(o => o.Image)
  .Prefetch(o => o.Image.Property)
  .Prefetch(o => o.Image.Area)
  .Prefetch(o => o.Image.Asset)
  .Prefetch(o => o.Property.Image)
  .Prefetch(o => o.Property.Beneficiary)
  .Prefetch(o => o.Property.LookUpPropertyType)
  .Prefetch(o => o.Property.LookUpPropertyType.LookupType)
  .Prefetch(o => o.Property.LookUpGarageType)
  .Prefetch(o => o.Property.LookUpGarageType.LookupType)
  .Prefetch(o => o.Property.LookUpPlumbingType)
  .Prefetch(o => o.Property.LookUpPlumbingType.LookupType)
  .Prefetch(o => o.Property.LookUpGarageType)
  .Prefetch(o => o.Property.LookUpGarageType.LookupType)
  .Prefetch(o => o.Property.LookUpRoofType)
  .Prefetch(o => o.Property.LookUpRoofType.LookupType)

Additionally, we could extend PrefetchSingle and PrefetchMany by the same way:

var owner = Query.All<Owner>()
  .Where(o => o.UserID == 512)
  .Prefetch(o => o.Beneficiary)
  .PrefetchSingle(o => o.Document, documents => ddocuments
    .Prefetch(d => d.Lookup)
    .Prefetch(d => d.BaseInsurance)
  )
  .PrefetchMany(o => o.Images, images => images
    .Prefetch(i => i.Property)
    .Prefetch(i => i.Area)
    .Prefetch(i => i.Asset)
  )

Note that ideally we must just extend prefetch expression on each of such 
.Prefetch calls, but convert it to our current representation only before 
enumeration (to properly handle A.B, A.C, A.D-like sequences).

Original issue reported on code.google.com by alex.yakunin on 21 Jun 2010 at 6:23

GoogleCodeExporter commented 9 years ago
More convenient version of prefetch API is described here: issue 720.

I.e. instead of making developers to call .Prefetch multiple times, we must 
provide: 

session.Prefetch<T>(IEnumerable<T> / T, params Func<T, object> paths);

Original comment by alex.yakunin on 20 Oct 2010 at 6:06