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).