none
Entity Framework / DBContext Objects RRS feed

  • Question

  • I have a question that has been posed to me and it very open ended, I believe I have one on the answers regarding stale data and 1st level cahce but part 2 not sure please answer if you can and documentation link.

    Q: When working with DbContexts what are two things you should never do on a production application

    • Moved by DotNet Wang Wednesday, December 21, 2016 2:23 AM Data related
    Tuesday, December 20, 2016 7:50 PM

All replies


  • Hi  James,

    >>When working with DbContexts what are two things you should never do on a production application

    As far as I know, the following points need attention.

    1: Do not use "using" or "Dispose DbContext" casually, it may lead to lazy loading is not available, there will be some other errors.

    2: You can call Dispose, but in most common scenarios you don’t need to.

    For example, the DbContext will be released off the database connection after the SaveChanges method completion.

    3: Avoid queries that use multiple Include statements

    Queries with multiple Include statements take a relatively long time to pass through the internal plan compiler in order to generate storage commands. Much of this time is spent trying to optimize the final query. This type of query will get a large number of connected graphs from the database in a single load, worsening all bandwidth issues.


    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 21, 2016 10:01 AM
    Moderator
  • I appreciate at the response I will dig into lazy loading

    james

    Thursday, December 29, 2016 12:29 AM