启动/首次查询非常慢 [英] Startup/first query extremely slow

查看:109
本文介绍了启动/首次查询非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建/编译我的DbContext需要花一些时间(超过3分钟)。网络服务器启动大约需要5秒钟,但是当我对数据库进行第一次查询时,EF 2.0必须在内存或其他内容中构建/创建/编译数据库吗?下一个请求几乎是即时的。这是DbContext的数据库首次创建,该数据库已存在于MSSQL中并具有数据。 DbContext包含约500个具有关系的DbSet。

It takes a while (3 minutes+) to 'create/compile' my DbContext. The web server starts in about 5 seconds, but when I do the first query to my database, EF 2.0 has to 'build/create/compile' the database in memory or something, I think? The next requests are almost instant. This was a Database First creation of the DbContext, the database already exists in MSSQL and has data. The DbContext contains about 500 DbSet's with relations.

是否有一种方法可以通过在运行对象之前执行我的实体框架的DbContext的创建(映射?)来加快此过程。 Web服务器(在开发时)创建所需的文件/映射,因此第一个请求也很快吗?

Is there a way to speed this up by doing the 'creation(mapping?)' of my Entity Framework's DbContext before running the web server (at developmenttime), create the file/mappings it needs, so the first request is fast too?

推荐答案

默认情况下,这是正常的Entity Framework行为,但是从另一方面来看,有一些方法可以解决此问题。

In general this is normal Entity framework behavior by default, but from other side of cause there are some ways to resolve this course of things.

例如,您可以尝试:


  • 禁用数据库初始化

  • 使用前代视图

  • 温暖 loading

请尝试阅读以下文章:

  • https://msdn.microsoft.com/en-us/library/hh949853(v=vs.113).aspx
  • https://www.fusonic.net/en/blog/3-steps-for-fast-entityframework-6.1-code-first-startup-performance/
  • https://www.fusonic.net/en/blog/ef-cache-deployment/

这篇关于启动/首次查询非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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