gpt4 book ai didi

c# - 为什么我的 WCF 数据服务无法提供自动生成的 ADO.Net EDM?

转载 作者:太空狗 更新时间:2023-10-29 18:31:49 24 4
gpt4 key购买 nike

我正在尝试按照本教程进行操作:http://msdn.microsoft.com/en-us/data/gg601462.aspx设置 ODATA 服务。我使用向导从我的 SQL Server 数据源创建(使用向导)和 ADO.NET 实体数据模型。

然后我设置了一个 WCF 数据服务,并告诉它使用实体。它没有提供数据,而是产生了一个不透明的服务器错误,我可以通过将其添加到服务器类 def 之上来降低不透明性:

[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]

因此我实际上可以看到错误。从“通常是 java”程序员的角度来看,这看起来像是一个类转换错误。这看起来很奇怪,因为我在新安装的试用版 VS Pro 2013 中学习教程

有人能理解这个错误并告诉我如何解决这个问题吗?


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, ReadOnlyCollection<code>1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable</code>1 parameters) at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, Boolean tailCall, IEnumerable<code>1 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</code>1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider& metadataProviderInstance, IDataServiceQueryProvider& queryProviderInstance, Object& dataSourceInstance, Boolean& isInternallyCreatedProvider) at System.Data.Services.DataService<code>1.CreateProvider() at System.Data.Services.DataService</code>1.EnsureProviderAndConfigForRequest() at System.Data.Services.DataService<code>1.HandleRequest() at System.Data.Services.DataService</code>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

最佳答案

感谢 Witbrock 的提示。

总结一下最终的解决方案,来自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.

注意:链接已更新为 beta2,因为 alpha1 不再有效。

关于c# - 为什么我的 WCF 数据服务无法提供自动生成的 ADO.Net EDM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19779964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com