locked
Slow object materialization? RRS feed

  • Question

  • Hello all

    I am converting an existing database / application and am exploring using EF 4 as part of the new middle-tier layer.  I have generated a model from the database, all good.  Now I'm trying to retrieve a single "business object" (identified by key), including all it's child objects (i.e. an object-graph).  I'm using the following LINQ

    from v in L0
       .Include( "L1_1" )
       .Include( "L1_2" )
       .Include( "L1_3" )
       .Include( "L1_4" )
       .Include( "L1_5.L2_1" )
       .Include( "L1_5.L2_2" )
       .Include( "L1_5.L2_3.L3_1" )
       .Include( "L1_5.L2_4" )
       .Include( "L1_5.L2_5" )
       .Include( "L1_5.L2_6" )
       .Include( "L1_5.L2_7" )
       .Include( "L1_5.L2_8" )
       .Include( "L1_5.L2_9.L3_2" )
       .Include( "L1_5.L2_10.L3_3.L4_1" )
       .Include( "L1_5.L2_10.L3_4" )
       .Include( "L1_5.L2_10.L3_5" )
       .Include( "L1_5.L2_10.L3_6" )
       .Include( "L1_5.L2_10.L3_7" )
    where v.PrimaryKey == 123
    select v

    Yes, there are over 20 tables here, up to 4 levels 'deep'. 

    When executed, this statement takes around 14 seconds to complete.  Testing the generated SQL statement directly against the database shows that it is less that 2 seconds of the total.  Most of the time appears to be processing the result-set, and building the object-graph in memory.  CPU (for one thread) sits on 100% through this period.

    The result-set only contains 100 rows (although with all these tables there are 100's of columns).

    I'm surprised at how slow the object materialization is.  Have I missed something?

    It's not a 'first time' cost (subsequent runs, using the same ObjectContext take roughly the same time).  I tried turning off change tracking, also no difference.

    Thanks in advance for any advice.

    Wednesday, June 6, 2012 2:03 AM

Answers

All replies