【发布时间】:2010-02-11 16:17:52
【问题描述】:
我有一个问题,我两次调用一个存储的过程,每个都有不同的参数,我需要 2 个单独的列表,但 linq 正在缓存数据并给我上面的错误
我尝试了 2 种不同的方法来绕过错误消息,一种在 tbl 上使用 ToList(),另一种手动遍历数据
我的代码如下所示
获取总数的代码
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);
db.MeterTotalConsumpRecordSet.MergeOption = System.Data.Objects.MergeOption.NoTracking;
var tbl = from t in db.GetTotalConsumptionByMeter(dtStart, dtEnd, (int) ug, nMeterSelectionType, nCustomerID, nUserID, strSelection, bClosedLocations, bDisposedLocations, 1)
select t;
List<MeterTotalConsumpRecord> objList = new List<MeterTotalConsumpRecord>();
foreach (MeterTotalConsumpRecord objRecord in tbl)
{
objList.Add(objRecord);
}
return objList;
}
public static List<MeterTotalConsumpRecord> GetTotalDayConsumption(DateTime dtStart, DateTime dtEnd, EUtilityGroup ug, int nMeterSelectionType, int nCustomerID,
int nUserID, string strSelection, bool bClosedLocations, bool bDisposedLocations)
{
dbChildDataContext db = DBManager.ChildDataConext(nCustomerID);
db.MeterTotalConsumpRecordSet.MergeOption = System.Data.Objects.MergeOption.NoTracking;
var tbl = from t in db.GetTotalConsumptionByMeter(dtStart, dtEnd, (int)ug, nMeterSelectionType, nCustomerID, nUserID, strSelection, bClosedLocations, bDisposedLocations, 3)
select t;
return tbl.ToList();
}
{
...Code for setting properties using parameters..
_P2Totals = ProfileDataService.DataService.GetTotalAllTimesConsumption(_P2StartDate, _P2EndDate, EUtilityGroup.Electricity, 1, nCustomerID, nUserID, strLocations, bIncludeClosedLocations, bIncludeDisposedLocations);
_P1Totals = ProfileDataService.DataService.GetTotalAllTimesConsumption(_StartDate, _EndDate, EUtilityGroup.Electricity, 1, nCustomerID, nUserID, strLocations,
bIncludeClosedLocations, bIncludeDisposedLocations);
PopulateLines() //This fills up a list of objects with information for my report ready for the totals to be added
PopulateTotals(_P1Totals, 1);
PopulateTotals(_P2Totals, 2);
}
第二次进入 GetTotalAllTimesConsumption 时出现错误
有没有办法可以回到列表的开头?有一个名为 FirstOrDefault 的方法不确定这是否有帮助?
干杯
保罗
【问题讨论】:
-
请格式化您的代码。
标签: linq linq-to-sql linq-to-objects