Reputation: 5089
I got this error message while querying the top 50 row in a table. My project uses Entity Framework 4 CTP 5 POCO:
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery' to type 'System.Linq.IQueryable`1[Lib.Model.Post]'
My Models was based on this answer: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable
Any idea on how to fix this error?
Thanks.
Upvotes: 1
Views: 962
Reputation: 5089
After changing the DataService context and override the ObjectContext, the service is now working. Here's what I've changed in case anyone also run into the same problem:
public class KennyService : DataService<MyDataContext>
{
// Codes
}
to
public class KennyService : DataService<System.Data.Objects.ObjectContext>
{
// Codes
}
protected override ObjectContext CreateDataSource()
{
var context = ((IObjectContextAdapter)new Lib.MyDataContext()).ObjectContext;
context.ContextOptions.ProxyCreationEnabled = false;
return context;
}
Upvotes: 2