I have extended my entities to implement specific interfaces for its type. I am trying to perform the following query:
var results = from x in context.MyEnt
If you want to cast your results to a complex type, you need to force the code to use LINQ to Objects rather than LINQ to Entities.
Calling the AsEnumerable
extension method before the cast is the trick here.
Try the following:
var results = from x in context.MyEntityTable
where x.AProperty == AValue
select x;
return results.AsEnumerable().Cast().ToList();
Also note that it's not wise to check Count()
on the enumerable, since it means the collection is iterated over twice.