Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing DbContext of 500+ tables database takes over 3 minutes every application restart #10053

Closed
ngoov opened this issue Oct 12, 2017 · 3 comments

Comments

@ngoov
Copy link

ngoov commented Oct 12, 2017

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.

Is there a way to speed this up by doing the 'creation' 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?

The web application itself starts in about 5 seconds, which is acceptable. It's the first query through EF Core 2.0 that takes 3 minutes+. If I just show a HTML page, it is loaded after about 5 seconds. The same if I use ADO.NET, the query is shown after 2 seconds. It's the first query (even a simple db.Articles.FirstOrDefault()) that takes 3 minutes+, the subsequent query (any query) takes a normal 100ms or something.

I've tried this in debug as well as release.

Because probably EF is bootstrapping itself, which I'm asking if the result of this bootstrap can be cached, so that EF does not need to rebuild the whole bootstrap every run and instead read the cached version.

Further technical details

EF Core version: 2.0.0 (was same result on 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: tested on Windows 8, Windows 10, Windows Server 2016, Windows Server 2012 R2, same result on all
IDE: Visual Studio 15.3.5 (2017) Pro

@ajcvickers
Copy link
Contributor

@nfdevil There isn't anything like this at the moment--we are tracking some ideas as #1906. When working on this (or just doing model building perf work in general) it is useful to use a variety of larger models since there are many factors (annotations, number of relationships, etc.) that can impact model building perf. Would it be possible for you to share your model with us? If you don't want to post it on github, then feel free to email it to me--I am "avickers" working at microsoft.com.

@ngoov
Copy link
Author

ngoov commented Oct 17, 2017

@ajcvickers sure, it's the database model of a Dutch application that we are using internally. I've scaffolded it with the EF Core 2.0 Tools.
I've uploaded it to a repo: https://github.com/nfdevil/TopDeskDbContext

@ajcvickers
Copy link
Contributor

@nfdevil Many thanks. 👍

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants