Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my WCF Data Service not able to serve an automatically generated ADO.Net EDM?

Tags:

c#

.net

linq

wcf

odata

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, IEnumerable1 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.DataService1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider& metadataProviderInstance, IDataServiceQueryProvider& queryProviderInstance, Object& dataSourceInstance, Boolean& isInternallyCreatedProvider) at System.Data.Services.DataService1.CreateProvider() at System.Data.Services.DataService1.EnsureProviderAndConfigForRequest() at System.Data.Services.DataService1.HandleRequest() at System.Data.Services.DataService1.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

like image 429
Witbrock Avatar asked Nov 05 '13 00:11

Witbrock


1 Answers

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:

  1. 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.

  2. Replace the base type of your DataService. For EF 5 or below, your data service should inherit from DataService<T> where T is a DbContext or ObjectContext. For EF 6 or greater, your data service should inherit from EntityFrameworkDataService<T> where T is a DbContext.

NOTE: Link updated to beta2 as alpha1 does not work anymore.

like image 53
JDawg Avatar answered Oct 16 '22 05:10

JDawg