none
Why is the .Local property db DBContext so SLOW? RRS feed

  • Question

  • I have as ASP.NET application using Entity Framework 4.3.1.  In analyzing the performance of my application I discovered that nearly all of the processing time was spent in the get_Local function in DBContext.  This is a context containing ~60 table and ~4000 total records.  I found that each call to .Local was taking between .25 and .5 seconds.  That's a really long time for a relatively small set of data and it is forcing me to rewrite my application to not use the .Local property.  Has anyone else seen this type of performance issue?

    Monday, May 28, 2012 1:58 AM

Answers

  • Hi Mike,

    I think you get the helpful information from this link: http://stackoverflow.com/questions/5488611/entity-framework-code-first-reducing-round-trips-with-load-and-local

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 29, 2012 9:07 AM
    Moderator

All replies

  • Hi MikeEmerson,

    Welcome to MSDN Forum.

    Local method is used for access in-memory data for a dataset, so I think it will be very fast. Could you please create a simple test project to test the Local method individual? Just load the data from database into memory and call "context.dbset.Local", try to test whether it is low performance.

    Best Regards


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

    Tuesday, May 29, 2012 5:58 AM
    Moderator
  • Hi Mike,

    I think you get the helpful information from this link: http://stackoverflow.com/questions/5488611/entity-framework-code-first-reducing-round-trips-with-load-and-local

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 29, 2012 9:07 AM
    Moderator
  • I'm finding similar issues in my application.

    I've got a database with a table of about 16,500 cities.  I preload them into memory with the code: 

    Db.Cities.Load()

    ...then when it's time to use them, I've tried each of the following queries:

    Dim cities() As String = Db.Cities.Select(Function(c) c.CityName).ToArray
    
    Dim cities() As String = Db.Cities.Local.Select(Function(c) c.CityName).ToArray

    The first query is fast (~10ms), but the second one takes about 2.3 seconds to run the first time (although it's faster than the first query when it's called after that).  This doesn't make sense because SQL Server Profiler verifies that the first query is hitting the database on another machine, but the second isn't!

    Friday, August 31, 2012 9:55 PM