I have a stored procedure that I call through the Entity Framework.
The stored procedure has 2 date parameters. I supply 2 times different arguments when I call a stored procedure. I checked with SQL Profiler that the stored procedure is called correctly and returns the correct results.
When I call my method for the second time with different arguments, although the stored procedure returns the correct results, the created table contains the same data as the first time I called it.
dtStart = 01/08/2009
dtEnd = 31/08/2009
public List<dataRecord> GetData(DateTime dtStart, DateTime dtEnd)
{
var tbl = from t in db.SP(dtStart, dtEnd)
select t;
return tbl.ToList();
}
GetData((new DateTime(2009, 8, 1), new DateTime(2009, 8, 31))
GetData(new DateTime(2009, 7, 1), new DateTime(2009, 7, 31))
Is this an example that the Entity Framework is smart and caching? I don’t understand why he will cache this, because since he executed the stored procedure twice.
- , tbl?
- Visual Studio 2008 + Entity Framework.
- " " , , , ?
FULL CODE LISTING
namespace ProfileDataService
{
public partial class DataService
{
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();
}
}
}
List<MeterTotalConsumpRecord> _P1Totals;
List<MeterTotalConsumpRecord> _P2Totals;
public void LoadData(int nUserID, int nCustomerID, ELocationSelectionMethod locationSelectionMethod, string strLocations, bool bIncludeClosedLocations, bool bIncludeDisposedLocations,
DateTime dtStart, DateTime dtEnd, ReportsBusinessLogic.Lists.EPeriodType durMainPeriodType, ReportsBusinessLogic.Lists.EPeriodType durCompareToPeriodType, ReportsBusinessLogic.Lists.EIncreaseReportType rptType,
bool bIncludeDecreases)
{
_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()
PopulateTotals(_P1Totals, 1);
PopulateTotals(_P2Totals, 2);
}
void PopulateTotals(List<MeterTotalConsumpRecord> objTotals, int nPeriod)
{
MeterTotalConsumpRecord objMeterConsumption = null;
foreach (IncreaseReportDataRecord objLine in _Lines)
{
objMeterConsumption = objTotals.Find(delegate(MeterTotalConsumpRecord t) { return t.MeterID == objLine.MeterID; });
if (objMeterConsumption != null)
{
if (nPeriod == 1)
{
objLine.P1Consumption = (double)objMeterConsumption.Consumption;
}
else
{
objLine.P2Consumption = (double)objMeterConsumption.Consumption;
}
objMeterConsumption = null;
}
}
}
}