none
Entity Framework 5 Performance on Views Generation RRS feed

  • Question

  • We are using EF 5 Code First to map about 300 entities (wich means 6000 properties and 1000 foreign keys - all FK have a 'int' property according to http://msdn.microsoft.com/en-us/data/hh949853.aspx).

    I develop a very simple test to ensure the performance of EF initialization:

    1: System.Data.Entity.Database.SetInitializer<Context300>(null);
    2: Context300 context300 = new Context300();
    3: contexto.Database.Connection.Open();
    4: contexto.Database.Connection.Close();
    5: context300.Configuration.AutoDetectChangesEnabled = false;
    6: var table2 = (from t in context300.Table2s select t).FirstOrDefault();
    7: var table3 = (from t in context300.Table3s select t).FirstOrDefault();

    Lines 1 and 2 take less than 1 second. Lines 3 and 4 just enruse that's no SGBD related issue and takes less than 1 second too.

    The line 6 take about 80 seconds to run and according to profiler it's used by EF and not related to SGBD communication. The line 7 take less than 1 second as the EF has all views generated.

    In a second scenery I used pre-generated views (EF Power Tools) and the time of the line 6 drop from 80 to 13 seconds but the compile time take too long.

    My question is, besides split my context in multiple context, is there some other options?

    Friday, June 22, 2012 3:09 PM

Answers

  • Hi Max André Bündchen,

    Welcome to MSDN Forum.

    You can also use compiled query to improve the performance.

    Here's a good article which introduces all the scenarios of improving performance with EF5, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 25, 2012 5:28 AM
    Moderator

All replies

  • Hi Max André Bündchen,

    Welcome to MSDN Forum.

    You can also use compiled query to improve the performance.

    Here's a good article which introduces all the scenarios of improving performance with EF5, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 25, 2012 5:28 AM
    Moderator
  • Allen, thanks for welcome.

    Based on your sugested article I could determine that the additional time in the first query points to 'metadata loading'. The 13 seconds I found at least 11 is metadata loading (the views are precompiled so take less than 2 secons and the query execution is about 1/10 a second).

    At this time I believe there's no way to serialize the metadata loading to make this 13 seconds better yet at first query.

    Tuesday, June 26, 2012 1:14 PM
  • Hi Max André Bündchen,

    Based on this issue, I suggest yo to split entitites into multiple context, this is, so the step of loading metadata will cost fewer time.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 27, 2012 2:23 AM
    Moderator