Linq-to-sql Compiled Query is caching result from disposed DataContext

Posted by Vladimir Kojic on Stack Overflow See other posts from Stack Overflow or by Vladimir Kojic
Published on 2010-03-18T19:31:02Z Indexed on 2010/03/18 19:41 UTC
Read the original article Hit count: 517

Filed under:

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

© Stack Overflow or respective owner

Related posts about linq-to-sql