Can someone tell me why the following code results in a dirty session?
Code:
using (ITransaction t = CurrentSession.BeginTransaction())
{
IQuery query = CurrentSession.CreateQuery("from SensorHistory srh "
+ "where srh.Sensor = :sensor "
+ "and srh.ReadingTimeUTC between :startDate and :endDate");
query.SetParameter("sensor", sensor);
query.SetParameter("startDate", startDateUTC);
query.SetParameter("endDate", endDateUTC);
var list = query.List<SensorHistory>();
t.Commit();
}
If I check the "CurrentSession.IsDirty()" before query.List<SensorHistory>() it returns false but true after. The problem is these entities come from a large table so when the enclosing transaction is committed, it tries to write these entities back to the DB, which causes a table scan that takes a very LOONNGGG time.
Thanks,
Dave