Search code examples
.netwcfodataentity-framework-6

Using WCF Data Services 5.6.0 with Entity Framework 6+


I have been trying to get our WCF Data Service to work with the new Entity Framework 6.

I found this article which explains a supposedly easy and painless way to fix this issue.

I followed the directions posted exactly. When I first install:

Install-Package Microsoft.OData.EntityFrameworkProvider -Version 1.0.0-alpha1 -Pre

I get the error:

Error 16 The type 'Microsoft.OData.Service.DataService`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.OData.Service, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. C:\Realtime Source\RTR 6.x\RTRServices\RTRWCFDataService\RTRWCFDataService\RTRWCFData.svc.cs 21 16 RTRWCFDataService

Upon researching that it seems that the solution is to upgrade to alpha 2... and to do this use the command:

Install-Package Microsoft.OData.EntityFrameworkProvider -Pre 

When I use this command the Package Manager Console spits out two errors:

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load type 'System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand' from assembly 'E ntityFramework.PowerShell, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'." At C:\Realtime Source\RTR 6.x\RTRServices\RTRWCFDataService\packages\EntityFramework.6.0.1\tools\EntityFramework.psm1:698 char:31 + $domain.CreateInstanceFrom <<<< ( + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load type 'System.Data.Entity.ConnectionFactoryConfig.AddProviderCommand' from assembly 'EntityFramework .PowerShell, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'." At C:\Realtime Source\RTR 6.x\RTRServices\RTRWCFDataService\packages\EntityFramework.6.0.1\tools\EntityFramework.psm1:698 char:31 + $domain.CreateInstanceFrom <<<< ( + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

Then I lose the ability to access the Microsoft.OData namespace... basically keeping me from the class that I need to finish the upgrade Microsoft.OData.Service.Providers.EntityFrameworkDataService

Any help at all on this issue would be greatly appreciated!


Solution

  • While I was able to install the Alpha 2 release, I've run into quite a few issues with this provider. Many of them yield unclear or misleading exceptions, as you can find in the comments of the original announcement. And, currently, the developers aren't actively engaging the community in working through the issues. In fact, given that nearly two months have passed since the last Alpha release, it's unclear whether or not this is a priority within Microsoft.

    Given this, I wouldn't recommend basing any production code on this provider. In fact, I'd be hesitant to even develop against it with the hope that a more stable version will release later until we've seen more momentum behind this version of the library. My suspicion is that with the release of ASP.NET Web API 2.0, WCF Data Services has been put on the back burner.

    Until then, you're probably better off pursuing one of the following options:

    This probably isn't the answer you're hoping for, nor does it address your immediate hurdle, but until there's more movement on the official provider I'd consider these options instead.

    * Breeze is a client JavaScript library for consuming oData services, but it also includes a server-side library for interfacing with popular O/RMs, including Entity Framework 6.0 as well as NHibernate.