Incorrect item retrieved from Cache?

Feb 19, 2010 at 12:25 AM

I am querying a table and then iterating over the retrieved values a little later in my code against a related table. When I iterate the second time through the 'child' table, I receive an error from that I cannot cast between the parent and child tables.


Exception: Unable to cast object of type 'System.Linq.EnumerableQuery`1[Test.Customer]' to type 'System.Collections.Generic.IEnumerable`1[Test.Order]'.

To reproduce this, I simplified the scenario down to the following snippet to drop into the northwind perf test:

public void Test()
{
var customersQuery = from c in db.Customers select c;
var qcache = new QueryCache(10);
var customers = qcache.Execute(customersQuery).ToList();
foreach (Customer customer in customers)
{
IEnumerable<Order> Orders =
qcache.Execute(
from row
in db.Orders
where row.CustomerID == customer.CustomerID
select row).ToList();
}
}

I have entered this into the issue tracker as well. 

 

Thanks!

Bart