实体框架有时不检索最近插入的值 [英] Entity Framework some time doesn't retrieve recently inserted values

查看:77
本文介绍了实体框架有时不检索最近插入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



希望你表现得很好。正如这个问题的标题描述了我所面临的问题。所以我还在下面写下详细信息。



我使用实体框架4进行DAL,在我的帮助库中有共享/静态datacontext对象,它基本上指向DAL。每当页面上的任何操作需要datacontext对象时。共享/静态datacontext对象返回到页面。我正在使用带有LazyLoadingEnabled = False的datacontext对象。这就是关于如何在我的页面上使用datacontext对象的全部



现在解决这个问题。每当我使用实体框架进行插入,删除或更新操作时,它都会在操作之后描绘更改(没有问题)。当我在实体框架中使用存储过程进行任何操作时。有时它不会在操作后描绘更改。在一段时间(约5分钟)之后,可以在应用程序端看到更改。当我查看数据库时(在实体框架中使用存储过程之后),存在更改。它并没有每次都表现出这种烦人的行为。



现在我的问题是



1)这种行为是由于共享/静态数据上下文对象造成的。

2)如果共享/静态数据上下文对象不是问题,那么为什么会出现这种恼人的行为。

Hello Everyone

Hope you are doing well. As the title of this question depicts that what sort of issue i am facing. So furthermore i am writing the details below.

I have DAL using Entity framework 4 and in my helper library there is shared/static datacontext object which basically points to DAL. Whenever datacontext object is needed for any operation on page. The shared/static datacontext object is returned to the page. I am using datacontext object with LazyLoadingEnabled = False. That is all about how the datacontext object is used on my pages

Now comming to the problem. Whenever i do insertion, deletion or updation operation using entity framework, it portrays the changes after the operation (no issue). When i used stored procedure in entity framework for any operation. Some times it doesn't portrays the changes after the operation. After sometime(about 5 min) changes can be seen on the application side. When i look into the database (After using stored procedure in entity framework) changes are there. It is not showing this annoying sort of behavior every time.

Now my question is

1) Is this behavior due to shared/static data context object.
2) If shared/static data context object isn't the problem, then why this annoying behavior.

推荐答案

听起来好像当你正在进行更新时,你要么不是在调用SaveChanges,要么是在处理上下文实例时依赖它来调用它。



另一种可能性就是你'重新使用某种缓存方案,而不是正确管理对象的缓存。
It sounds as though you're either not calling SaveChanges when you're making the updates or are relying on it being called when the context instance is being Disposed.

Another possibility is you're using some kind of caching scheme and you're not managing the cache of your objects properly.


这篇关于实体框架有时不检索最近插入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆