I'm working on a basic CRUD application in .Net MVC using EF code first.
I've come across an issue I've never really come across before.
Basically any changes I make to the database backend aren't being reflected in the application unless I reboot the website on the server, or re-deploy the app.
I've got another app in development and it has the exact same issue.
Any changes I make using the app are fine but any manual updates to the SQL backend aren't getting pulled through.
I'm pretty sure it isn't on the client side I've done a hard refresh, manually cleared all my browsing data and installed cache killer on my browser.
Any ideas how I can start debugging this issue?
Thanks
Here is what my db context file looks like:
public partial class MyContext: DbContext
{
public MyContext() : base("name=MyContext")
{
}
public DbSet<MyDbSet> MyDbsets { get; set; }
etc...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
I'm calling it in my MVC layer using unity:
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
// repos
...my repos
// service
... my serives
container.RegisterType<MyContext>(new HierarchicalLifetimeManager());
RegisterTypes(container);
return container;
}
I've set up dozens of apps in this way and never had this issue.. also don't understand the down vote.. it a genuine question
Using HierarchicalLifetimeManager
means that the context
instance returned has the same lifetime as the container (per session). If you always use the same container instance per session you will keep reusing the same context
instance, which is not recommended. You should always create a new context
instance for every "logical unit of work", and dispose of it afterwards. Contexts with long lifetimes can exhibit very strange behavior (usually manifested as "caching") and poor performance.
PerRequestLifetimeManager
will return a new instance of the context
each time you request it, which will take care of reusing the same context
instance over and over.