实体框架核心第一次加载缓慢 [英] Entity Framework Core Slow First Time Loading

查看:108
本文介绍了实体框架核心第一次加载缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理Entity Framework Core DbContext预热时间。我有非常大的DbContext,并且正在使用AddDbContextPool()选项注册DbContexes,该选项将DbContext注册为单例并由应用程序重用。

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.

在早期版本的EF中,以加快应用程序的启动时间,具体方法如下:使用缓存的DbModelStore,使用NGen生成预编译的视图和/或生成实体框架的预编译版本,以免发生抖动。

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.

但是,我没有看到在Entity Framework Core上应用这些方法的任何有效方法。我什至找不到其他方法来避免DbContext的初始启动/蠕虫启动时间。

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.

我们的应用程序的蠕虫启动时间约为30秒钟以上。

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

我尝试在我的应用程序首次启动时初始化DbContextes,但这似乎不是一个优雅的或事件可承受的解决方案。

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

Entity Framework Core团队(Github)上有一个对已编译视图的功能请求,但是,该功能没有最后期限。

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.

谢谢

推荐答案

由于EF配置表映射,首次启动很慢。您可以做的最重要的事情是重新设计dbcontext。您必须将配置分成不同的上下文。一个上下文必须包含很少的实体,这些实体在含义上相关联(就像在DDD中一样)。例如。 UserDbContext(用于授权。提供用户,令牌,personalData ...),CustomerDbContext(提供所有客户数据:客户,联系人,合同,报价...)

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...)

这篇关于实体框架核心第一次加载缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆