简体   繁体   English

奇怪的缓存问题EF代码优先应用程序SQL Server 2014

[英]Weird Caching Issue EF Code First Application SQL Server 2014

I'm working on a basic CRUD application in .Net MVC using EF code first. 我正在首先使用EF代码在.Net MVC中开发基本的CRUD应用程序。

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. 我使用该应用程序进行的任何更改都可以,但是对SQL后端的任何手动更新都没有完成。

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: 我在我的MVC层中使用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). 使用HierarchicalLifetimeManager意味着返回的context实例具有与容器相同的生存期(每个会话)。 If you always use the same container instance per session you will keep reusing the same context instance, which is not recommended. 如果每个会话始终使用相同的容器实例,则将继续重用相同的context实例,不建议这样做。 You should always create a new context instance for every "logical unit of work", and dispose of it afterwards. 您应该始终为每个“逻辑工作单元”创建一个新的context实例,然后再进行处理。 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. 每当您请求PerRequestLifetimeManager它将返回该context的新实例,这将负责一遍又一遍地重用同一context实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM