实体框架的问题:检索缓存值而不是最近的变化 [英] Entity Framework Problems: Retrieving cached values instead of recent changes

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

问题描述

我有透过表循环一个存储过程,它可能会在该表中插入一些记录。其工作罚款。我可以使用Management Studio看到分贝的变化。

问题是后,我会打电话给另一个存储过程将返回一个集合。但它始终返回一个缓存的值或者类似的东西在数据库.The最新变化不会返回列表中的反映。任何想法?

修改

我导入存储过程使用EF工作。所有我做的操作是通过EF。
赤以下code

  TraktorumEntities DB =新TraktorumEntities();
VAR测试= db.GetAvailableAttributes(类别id).ToList(); //这里我得到的缓存值我。怎么可以强制来从数据库数据


解决方案

如果您使用的是同一个键查询,EF都会有结果的缓存。

请注意的部分MergeOption.OverwriteChanges在这里

演练:映射一个实体存储过程(实体数据模型工具)
你需要告诉EF为获取新数据并覆盖本地存储的版本使用此选项。

另外,你真的不告诉我们到底怎么样,你要么查询这些数据。这是映射存储过程(映射到​​实体操作)或直接调用其上的背景下,或....?

修改
尝试沿着这些路线的东西。


VAR测试= db.GetAvailableAttributes(类别id)
test.MergeOption = MergeOption.NoTracking;
VAR的结果= test.ToList()

I have a stored procedure that loops through a table and it may insert some records in to that table . Its working fine . I can see the changes in db using management studio .

The problem is after that i will call another stored procedure which will return a collection .But it always return a cached value or something like that .The latest changes in db not reflecting in the returned list .Any ideas?

EDIT

I am importing stored procedure to function using EF. All the operations i made is via EF. Chek following code

 TraktorumEntities db = new TraktorumEntities();
var test= db.GetAvailableAttributes(CategoryID).ToList(); // here i get cached values  .How can i force to fetch data from data base 

解决方案

If you are querying using the same key, EF will have your results cached.

Note the section of "MergeOption.OverwriteChanges" here

Walkthrough: Mapping an Entity to Stored Procedures (Entity Data Model Tools) You need to tell EF to 'get new data and overwrite the locally stored version' with this option.

Also you don't really tell us exactly how you are querying this data either. Is this a mapped stored procedure (mapped to an entity operation) or calling it directly on the context, or....?

EDIT Try something along these lines

var test= db.GetAvailableAttributes(CategoryID)
test.MergeOption = MergeOption.NoTracking;
var results = test.ToList()

这篇关于实体框架的问题:检索缓存值而不是最近的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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