简体   繁体   English

实体框架核心第一次加载缓慢

[英]Entity Framework Core Slow First Time Loading

I am dealing with Entity Framework Core DbContext Warm Up time. 我正在处理实体框架核心DbContext热身时间。 I have very large DbContext, and I am registering out DbContexes with AddDbContextPool() option, which register DbContext as a singleton and application reuses it. 我有非常大的DbContext,我正在使用AddDbContextPool()选项注册DbContexes,它将DbContext注册为单例并且应用程序重用它。

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. 在早期版本的EF中,为了加快应用程序启动时间,应用了周围环境:使用Cached DbModelStore,生成预编译视图,和/或使用NGen生成预编译版本的实体框架以避免抖动。

However, I dont see any valid way of applying these on Entity Framework Core. 但是,我没有看到在Entity Framework Core上应用这些的任何有效方法。 I even could not find any other way of avoiding initial start-up / worm-up time of the DbContext. 我甚至找不到任何其他方法来避免DbContext的初始启动/蠕动时间。

The worm up time of our application is arround 30+ seconds. 我们的应用程序的蠕虫启动时间大约为30秒。

I tried to initialize DbContextes when my application first starts however this doest seems an elegant or event affordable solution. 当我的应用程序第一次启动时,我尝试初始化DbContextes但是这个doest似乎是一个优雅或事件可负担的解决方案。

there is a feature request for compiled views on Entity Framework Core team (Github) however, there is no deadline for this feature. 有关Entity Framework Core团队(Github)的已编译视图的功能请求,但此功能没有截止日期。

I need to know if there is any workaround and/or solution which I can apply. 我需要知道是否有可以应用的解决方法和/或解决方案。

Thank you 谢谢

First start is slow because EF configuring table mappings. 首先启动很慢,因为EF配置表映射。 Most important thing that you can do is to redesign you dbcontext. 您可以做的最重要的事情是重新设计dbcontext。 You must split configurations into different contexts. 您必须将配置拆分为不同的上下文。 One context must contains few entities, associated in meaning (as is done in DDD). 一个上下文必须包含几个与意义相关联的实体(如在DDD中所做的那样)。 Eg UserDbContext (for authorization. Provides users, tokens, personalData...), CustomerDbContext (provides all customer data: customers, contacts, contracts, offers...) 例如UserDbContext(用于授权。提供用户,令牌,personalData ...),CustomerDbContext(提供所有客户数据:客户,联系人,合同,优惠......)

I ran into difficulty with dbContext warm up times as we have one really big dbContext, or shall I say had. 因为我们有一个非常大的dbContext,所以我遇到了dbContext热身时间遇到了困难,或者我应该说。 To resolve it we now have multiple dbContexts for differing parts of the application. 为了解决这个问题,我们现在有多个dbContexts用于应用程序的不同部分。 It does come highly recommended. 它强烈推荐。

Then use the old data annotations [NotMapped] property to close off your dbcontexts. 然后使用旧数据注释[NotMapped]属性来关闭dbcontexts。 DBContext slow when initially building DBContext在最初构建时很慢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM