Linq-to-sql Compiled Query is caching result from disposed DataContext
- by Vladimir Kojic
Compiled query:
public static Func<OperationalDataContext, short, Machine>
QueryMachineById =
CompiledQuery.Compile((OperationalDataContext db, short machineID) =>
db.Machines.Where(m => m.MachineID == machineID).SingleOrDefault());
It looks like compiled query is caching Machine object and returning the same object even if query is called from new DataContext (I’m disposing DataContext in the service but I’m getting Machine from previous DataContext).
I use POCOs and XML mapping.
Getting cached object from the same datacontext is ok, but when I call query with new DataContext I don’t want to get object from old datacontext.
Is there something that I don’t do right ?
Thanks,
Vladimir