开发者

WCF Data Services and EF 4 CTP 5 POCO - Unable to cast Unable to cast object of type '...DbQuery' to type 'System.Linq.IQueryable`

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 'Sys开发者_如何学编程tem.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.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜