0

C# 4.0 + Entity Framework

In the database project that I'm currently working on, we have a very large growing dataset of multiple tables. They are nested pretty deep (about 60 tables in all). Most of the time we need a large chunk of the data. I had resorted to eager loading of all of the data but then I noticed that the data being returned via the generated SQL statement (about 300 columns) was in some cases 20x the total data size (there are a few large nvarchar columns). So I decided that lazy load was the better option (and to my surprise 10x faster).

I'm still trying to squeak out a little performance. Now each of our tables has an audit table. This table is more or less the active audit record. Since each table has a reference to this, when I lazy load the data I'm seeing 60 data calls to audit. It would make sense here to eager load this with the active record it's attached to.

So, is it possible to lazy load key records but for child records (say 2 levels deep in the hierarchy), force an eager load of the sub children therein.

  • Order
  • Audit
  • Payment
  • Audit
    • Payment Detail
      • Audit
  • Tracking
  • Audit
    • Tracking Detail
      • Audit

IDEAL:

  • Order + Audit
    • Payment + Audit
      • Payment Detail + Audit
    • Tracking + Audit
      • Tracking Detail + Audit

Also, it should be noted that these objects are serialized and passed to other app's on different systems that don't have direct access to the underlying data (as my college just said always lazy load since it'll be there when you need it).

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gary Smith
  • 61
  • 1
  • 10
  • look at here: http://stackoverflow.com/questions/6290306/partial-eager-loading-child-entity-load-specific-fileds – lem2802 Apr 23 '15 at 18:30
  • Is there a back reference from Audit to Order, Audit to Payment, etc? – Gert Arnold Apr 23 '15 at 20:22
  • There is a back reference from audit. I had through about preloading from that direction as well but since I don't know what the actual records will be until query time, I'm not sure if that would work. I'm interesting on your thoughts about it though. – Gary Smith Apr 24 '15 at 21:29
  • lem2802, I thought about that and saw that article, the challenge with that is that it still generates a rather large query and it doesn't solve the grandchild/greatgrandchild load example (without writing a rather large amount of code for each case. It will handle some of the simpler cases though and in place of eager loading I might pass a context in to the load method and selectively load other objects. Still looking at multiple approaches – Gary Smith Apr 24 '15 at 21:32

0 Answers0