Entity Framework Core Slow First Time Loading

杀马特。学长 韩版系。学妹 提交于 2019-12-10 17:25:17

问题


I am dealing with Entity Framework Core DbContext Warm Up time. I have very large DbContext, and I am registering out DbContexes with AddDbContextPool() option, which register DbContext as a singleton and application reuses it.

in an earlier version of EF, to speed up your application startup time following workarrounds are applied: Using a Cached DbModelStore, Generate pre-compiled Views, and/or Generate pre-compiled version of entity framework using NGen to avoid jitting.

However, I dont see any valid way of applying these on Entity Framework Core. I even could not find any other way of avoiding initial start-up / worm-up time of the DbContext.

The worm up time of our application is arround 30+ seconds.

I tried to initialize DbContextes when my application first starts however this doest seems an elegant or event affordable solution.

there is a feature request for compiled views on Entity Framework Core team (Github) however, there is no deadline for this feature.

I need to know if there is any workaround and/or solution which I can apply.

Thank you


回答1:


First start is slow because EF configuring table mappings. Most important thing that you can do is to redesign you dbcontext. You must split configurations into different contexts. One context must contains few entities, associated in meaning (as is done in DDD). E.g. UserDbContext (for authorization. Provides users, tokens, personalData...), CustomerDbContext (provides all customer data: customers, contacts, contracts, offers...)




回答2:


I ran into difficulty with dbContext warm up times as we have one really big dbContext, or shall I say had. To resolve it we now have multiple dbContexts for differing parts of the application. It does come highly recommended.

Then use the old data annotations [NotMapped] property to close off your dbcontexts. DBContext slow when initially building



来源:https://stackoverflow.com/questions/52423965/entity-framework-core-slow-first-time-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!