Share via

Entity Framework 6.1.3 Code first generating EDMX at runtime

Anonymous
2016-05-25T20:18:10+00:00

We are using Code First EntityFramework 6.1.3 (MSSQL 2014) and were having issues with performance of LINQ queries.

The first query would take 3.5secs after applying the patch suggest over here https://www.fusonic.net/en/blog/3-steps-for-fast-entityframework-6.1-code-first-startup-performance/

It worked and now it's 1.5 secs. We are still working on with pre-generated Views to make the LINQ calls under 1 sec.

I download the patch from codeplex.com and compiled EF. Has this been patched in EF released by Microsoft? or any other alternatives?

public class MyContextConfiguration : DbConfiguration { public MyContextConfiguration() { string cachePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\YOUR_APP_NAME\EFCache"; MyDbModelStore cachedDbModelStore = new MyDbModelStore(cachePath); IDbDependencyResolver dependencyResolver = new SingletonDependencyResolver(cachedDbModelStore); AddDependencyResolver(dependencyResolver); } private class MyDbModelStore : DefaultDbModelStore { private static bool useCachedDbModelStore; // Note that you should only enable DbContextStore during normal run scenarios without migrations. Migrations are currently not supported and will crash. public static void Configure(bool useCachedDbModelStore) { MyContextConfiguration.useCachedDbModelStore = useCachedDbModelStore; } public MyContextConfiguration() { // CachedDbModel store wird derzeit nicht immer verwendet, da er z.b. bei Migrations derzeit noch nicht funktioniert (Exceptions im EF Code) if (useCachedDbModelStore) { MyDbModelStore cachedDbModelStore = new MyDbModelStore(MyContext.EfCacheDirPath); IDbDependencyResolver dependencyResolver = new SingletonDependencyResolver(cachedDbModelStore); AddDependencyResolver(dependencyResolver); } } private class MyDbModelStore : DefaultDbModelStore { public MyDbModelStore(string location) : base(location) {} public override DbCompiledModel TryLoad(Type contextType) { string path = GetFilePath(contextType); if(File.Exists(path)) { DateTime lastWriteTime = File.GetLastWriteTimeUtc(path); DateTime lastWriteTimeDomainAssembly = File.GetLastWriteTimeUtc(typeof(TypeInYourDomainAssembly).Assembly.Location); if (lastWriteTimeDomainAssembly > lastWriteTime) { File.Delete(path); Tracers.EntityFramework.TraceInformation("Cached db model obsolete. Re-creating cached db model edmx."); } } else { Tracers.EntityFramework.TraceInformation("No cached db model found. Creating cached db model edmx."); } return base.TryLoad(contextType); } } } }

Windows for home | Windows 11 | Performance and system failures

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-05-26T21:39:43+00:00

    They should be able to help you there.

    Cheers.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-05-26T14:19:53+00:00

    cool ok

    Was this answer helpful?

    0 comments No comments