无法访问ObjectTrackingEnabled linq

时间:2010-02-08 00:43:33

标签: linq entity-framework

我遇到了一个问题,就好像第二次执行存储过程被忽略了一样。

我第一次调用我的存储过程时,它找到了20条记录,并提取了2009年8月日期范围内的信息。第一行是meter id 233,数据值为200

然后我调用了存储过程,还返回了20条记录。该时间表id 233的数据值为300.

Linq检测到上下文中已存在meterid 233,因此不会更新

我确信这与ObjectTrackingEnabled有关,但这似乎不适合我设置为false?

我没有编写上下文代码,所以我真的不知道它是如何工作的,但我注意到它似乎从ObjectDataContext继承

这是使用Entity Framework和VS 2008生成的

命名空间DataServiceDAL {

/// <summary>
/// There are no comments for dbChildDataContext in the schema.
/// </summary>
public partial class dbChildDataContext : global::System.Data.Objects.ObjectContext
{
    /// <summary>
    /// Initializes a new dbChildDataContext object using the connection string found in the 'dbChildDataContext' section of the application configuration file.
    /// </summary>
    public dbChildDataContext() : 
            base("name=dbChildDataContext", "dbChildDataContext")
    {
        this.OnContextCreated();            
    }
    /// <summary>
    /// Initialize a new dbChildDataContext object.
    /// </summary>
    public dbChildDataContext(string connectionString) : 
            base(connectionString, "dbChildDataContext")
    {
        this.OnContextCreated();
    }
    /// <summary>
    /// Initialize a new dbChildDataContext object.
    /// </summary>
    public dbChildDataContext(global::System.Data.EntityClient.EntityConnection connection) : 
            base(connection, "dbChildDataContext")
    {
        this.OnContextCreated();
    }
    partial void OnContextCreated();

.............. }

我使用以下linq来提取数据

    public static List<MeterTotalConsumpRecord> GetTotalAllTimesConsumption(DateTime dtStart, DateTime dtEnd, EUtilityGroup ug, int nMeterSelectionType, int nCustomerID, 
        int nUserID, string strSelection, bool bClosedLocations, bool bDisposedLocations)
    {    
        dbChildDataContext db = DBManager.ChildDataConext(nCustomerID);

        var tbl = from t in db.GetTotalConsumptionByMeter(dtStart, dtEnd, (int) ug, nMeterSelectionType, nCustomerID, nUserID, strSelection, bClosedLocations, bDisposedLocations, 1)                       
                  select t;                        

        return tbl.ToList();            
    }

我需要一种清除缓存的方法,以便正确更新对象或者我需要一种刷新对象的方法

有人可以帮忙吗?

干杯

1 个答案:

答案 0 :(得分:0)

我们建议您使用MergeOption刷新对象。 这是一个简单的例子:

var query = from d in context.Depts
                   where d.Deptno < 50
                   select d;
(query as ObjectQuery).MergeOption = MergeOption.OverwriteChanges;
相关问题