Entity Framework Core 首次加载缓慢 [英] Entity Framework Core Slow First Time Loading

查看:130
本文介绍了Entity Framework Core 首次加载缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 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(用于授权.提供用户、令牌、个人数据...)、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...)

这篇关于Entity Framework Core 首次加载缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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