1

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.

Community
  • 1
  • 1
Saxman
  • 5,009
  • 11
  • 51
  • 72
  • 1
    You need to provide more context. As it stands, I can play the amazing kreskin and attempt to devine all the possibilities. What is the code surrounding the error. – Gregory A Beamer Jan 31 '11 at 18:41

1 Answers1

2

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;
}
Saxman
  • 5,009
  • 11
  • 51
  • 72