-
-
Save davidroth/9886349 to your computer and use it in GitHub Desktop.
public class MyContextConfiguration : DbConfiguration | |
{ | |
public MyContextConfiguration() | |
{ | |
MyDbModelStore cachedDbModelStore = new MyDbModelStore(MyContext.EfCacheDirPath); | |
IDbDependencyResolver dependencyResolver = new SingletonDependencyResolver<DbModelStore>(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(MyDomain.SomeTypeInOurDomain).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); | |
} | |
} | |
} |
'DefaultDbModelStore' comming from his branch https://github.com/davidroth/entityframework/tree/DbModelStore
See related issues:
https://entityframework.codeplex.com/workitem/1876
https://entityframework.codeplex.com/workitem/2631
Hi,
I have already build DefaultDbmodelstore from the source code provided. Added the above class in my project but it never gets called. Could you please guide me????
I will be thankful to you,
@hugufc
Hi,
I have build and replaced the original DLL's of EntityFramework and EntityFramework.SqlServer with custom builds. It builds successfully however at runtime it keeps giving the followiong error
could not load file or assembly 'EntityFramework.SqlServer, Version=6.0.0.0,
I have spent hours searching and resolving but failed. Please can you help me resolve this error.
I will be thankful to you
Hey thanks for this example, and thanks @j-Edge for getting this into EF 6.2, I hope it gets released soon! I forked this code and changed it so the model only invalidates when the hash of the model file has changed. This is so I can keep the cached file across rebuilds, branch changes, and asp deployments. Let me know what you think of this approach if you have time to take a look at it - Thanks!
can u explain for me what is MyContext.EfCacheDirPath (i'm a beginer)
Hi, each time i run the application it rewrites .edmx files, that's why there is no luck, can you please advise what could be wrong? i debug the code and sure this line File.Delete(path); is not deleting the existing file. thanks
Hi,
Could you please let me know where is the 'DefaultDbModelStore' come from? I can't find from EF 6.1.
Thanks.
-Steven