I'm trying to follow this tutorial: http://msdn.microsoft.com/en-us/data/gg601462.aspx to set up an ODATA service. I created (using the wizard) and ADO.NET Entity Data Model from my SQL Server data source using the wizard.
Then I set up a WCF Data Service, and told it to use the entities. Instead of serving the data, it produced an opaque server error, which I was able to make less opaque by adding this above the server class def:
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
And therefore I can actually see the error. From the perspective of a "usually java" programmer, this looks like a class cast error. Which seems weird since I'm following the tutorial in a newly installed trial VS Pro 2013
Can someone understand the error and tell me how to get past this?
The server encountered an error processing the request. The exception message is 'Expression of type 'System.Data.Entity.Core.Objects.ObjectContext' cannot be used for return type 'System.Data.Objects.ObjectContext''. See server logs for more details. The exception stack trace is:
at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable
1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, Boolean tailCall, IEnumerable1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, ParameterExpression[] parameters) at System.Data.Services.Providers.DbContextHelper.CreateDbContextAccessor(Type type) at System.Data.Services.Providers.DbContextHelper.GetDbContextAccessor(Type type) at System.Data.Services.Providers.DbContextHelper.IsDbContextType(Type type) at System.Data.Services.DataService
1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider& metadataProviderInstance, IDataServiceQueryProvider& queryProviderInstance, Object& dataSourceInstance, Boolean& isInternallyCreatedProvider) at System.Data.Services.DataService1.CreateProvider() at System.Data.Services.DataService
1.EnsureProviderAndConfigForRequest() at System.Data.Services.DataService1.HandleRequest() at System.Data.Services.DataService
1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.S
Thanks for the tip Witbrock.
To sum up the final solution, from MSDN:
If you are upgrading an existing OData service to Entity Framework 6 or greater, you will need to do a couple of things:
Install the WCF Data Services Entity Framework Provider NuGet package. Since this package has a dependency on WCF Data Services 5.6.0 and Entity Framework 6 or greater, some of the other NuGet packages in your project may be upgraded as well.
Replace the base type of your DataService. For EF 5 or below, your data service should inherit from
DataService<T>
whereT
is aDbContext
orObjectContext
. For EF 6 or greater, your data service should inherit fromEntityFrameworkDataService<T>
whereT
is aDbContext
.
NOTE: Link updated to beta2 as alpha1 does not work anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With