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
Reduce start up time by loading finished code first models from a persistent cache #275
Comments
What is the recommended way to get notified when this is released (6.2)? |
@tlk Watch the repo ? |
@ErikEJ I would prefer to receive announcements only instead of project-wide chit-chat like this, but I'll watch the repo. Looking very much forward to the improvement on startup time. Thanks! |
@tlk Understand, this repo however is very quiet. Alternatively, subscribe to the .NET blog RSS feed. |
@divega How would i set this on DbMigrationsConfiguration(Of DataContext)? This is in DbConfiguration, but not in DbMigrationsConfiguration.
|
I have a question: is the DefaultDbModelStore suppose to be set as default in 6.2? |
@NicoJuicy this can only be set in a @michalczerwinski it is not set by default, you have to opt in explicitly. That is something we could consider for a future release if the serialization as well as the invalidation mechanism proves to be very reliable. |
This is as improvement of the code first mode , why you say it has to do with edmx file? edmx file isn't with the db first mode? |
@TimRowe the improvement serializes the computed code first model to an artifact that uses the edmx file format. I.e. the edmx becomes an implementation detail of code first when you are using this option. |
Hi,but if i use code first migrations , how i can do use persistent caching? My database configuration use dbmigrationsconfiguration and not use dbconfiguration |
FYI .. this item has been released! EF6.2.0 is out! |
@divega commented on 9 lip 2017, 09:19 CEST:
It means that is not possible to use persistent caching with DbMigrationsConfiguration? |
@SylwesterZarebski you can use both |
Could You share some code? Now i have:
where CheckAndMigrateDatabaseToLatestVersion is:
How can i add persistant caching? |
sure. this configuration for migrations:
and this configuration for chaching:
then you set attribute on your DbContext file:
|
Thanks, i'll try to use it that way. |
This is not working for me. What I did is very simple and I think exactly what has been suggested above: I saved the model using In my DbConfiguration implementation I set DbModelStore is my implementation of DefaultDbModelStore where I overwrite GetFilePath(). When making the first call to EntitySet I get I have been able to get it to work when I create a DbCompiledModel instead: I can then pass the model to the constructor of the context. However this is much more complicated mostly because of the stupid null check of the model in the constructor (!) so I have to make sure to call the right constructor overload depending on whether I already have a saved model or not. A fix for the null check or an explanation why the DefaultDbModelStore is not working would be appreciated. I consider both to be bugs. |
Created a new issue instead: #404 |
My project's start time is about 10 sec. I added this model caching feature public class ProductsDbConfiguration : DbConfiguration
{
public ProductsDbConfiguration() : base()
{
this.SetModelStore(new DefaultDbModelStore(AppDomain.CurrentDomain.BaseDirectory));
}
}
[DbConfigurationType(typeof(ProductsDbConfiguration))]
public class ProductsContext : DbContext
{...} Edmx file created succesffully on first run. What i'm doing wrong? Migration init code: // Global.asax.cs --------
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ProductsContext, Products.Infrastructure.Migrations.Configuration>());
// ---------
namespace Products.Infrastructure.Migrations
{
using System.Data.Entity.Migrations;
public sealed class Configuration : DbMigrationsConfiguration<Repositories.ProductsContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
CommandTimeout = 60 * 5;
}
}
} |
@ivanovevgeny It could be that Code First model creation is not the perf bottleneck. It might be worth reading EF perf white paper and checking to see if any of the guidance there can help. |
(Copied description from PR #40)
Ported from CodePlex Pull Request 8468
Fix for CodePlex Work Items #1876 and #2631
Reduce start up time by loading finished Code First models from a persistent cache
Incorporates DbModelStore persistent cache to reduce Code First Startup Time
With these changes, first AppDomain calls to context.Database.Initialize for a model with just over 600 models and a null initializer dropped from 12-14 seconds to about 1.9 seconds after the edmx was written, saving 10-12 seconds on initialization. The first call to write the edmx still ran in 12-14 seconds (no noticeable delay added).
Includes code from the patch by emilcicos attached to work item #1876, with modifications to fix known issues.
Code changed after applying the patch:
The text was updated successfully, but these errors were encountered: