Entity Framework model and view caching configuration from app.config

Dave Christianson 1 Reputation point
2021-01-19T06:24:38.27+00:00

I have multiple code first apps relying on multiple DbContexts in multiple assemblies. First query on some of the contexts can take up to 40 seconds to start up due to needing to read and validate all the model and view data.

Have read through the docs on using EDMX fields and pre-generated views. Trying to understand if there is a way to activate a custom pre-generated view cache for a context from configuration - for instance with a custom db configuration class specified in the entityFramework section of app.config - or would I need to make a custom section entirely?

The reasoning for doing this is that I want to test using both pre-generated EDMX and views across many apps but not change every app and definitely not change production code. There are a few third party libraries that provide these facilities but require code - particularly for the view caching - would prefer to only change config.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,439 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2021-01-19T08:40:41.63+00:00

    Hi DaveChristianson-7352,
    First, you can use the EF Power Tools Community Edition to pre-generate views.
    Then in order to load the views generated you can provide EF with a class that inherits from the DbMappingViewCache abstract class.
    More details you can refer to this document.
    You can also follow this document to improve the performance of EF.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments