【问题标题】:OData (WCF Data Service) with Subsonic 3带有 Subsonic 3 的 OData(WCF 数据服务)
【发布时间】:2011-04-08 07:17:13
【问题描述】:

我正在尝试将 WCF 数据服务与 Subsonic 一起使用,但是当我尝试访问我的“service.svc”时遇到了这个错误。我有 2 个项目,一个是一个类库(称为“OData”),它具有 Subsonic t4 模板来为我的表生成类。另一个是引用“OData”项目的 ASP.NET MVC2 项目。

然后我在我的 ASP.NET MVC 项目中创建一个名为“service.svc”的新 WCF 数据服务项,指向我从“OData”项目中获得的由 Subsonic 生成的“TestDB”上下文。根据这篇文章,我已经在我的“服务”类中添加了这个属性:http://theruntime.com/blogs/jaykimble/archive/2008/11/18/quotsubsonicquot-for-services-found-subsonic-3--ado.net-data-services.aspx

这是我的服务类的样子:

[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] 
public class Service : DataService<SymetraGivingDB>
{
   // This method is called only once to initialize service-wide policies.
   public static void InitializeService(DataServiceConfiguration config)
   {
      // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
      // Examples:
      // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
      // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
      config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
      config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
      config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
   }
}

当我尝试访问我的 http://localhost/Service.svc 时,我收到此错误:

请求错误

服务器在处理请求时遇到错误。
异常消息是'关于数据上下文类型 'SymetraGivingDB',有一个顶部 IQueryable 属性“用户”,其 元素类型不是实体类型。
确保 IQueryable 属性 是实体类型或指定 数据上的 IgnoreProperties 属性 上下文类型忽略这个 财产。'。查看服务器日志了解更多信息 细节。异常堆栈跟踪是:

在 System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadata(IDictionary2 knownTypes, IDictionary2 childTypes, IDictionary2 entitySets)
at System.Data.Services.Providers.BaseServiceProvider.PopulateMetadata()
at System.Data.Services.DataService
1.CreateProvider()
在 System.Data.Services.DataService1.HandleRequest()
at System.Data.Services.DataService
1.ProcessRequestForMessage(流 消息正文)
在 SyncInvokeProcessRequestForMessage(Object, Object[] , Object[] )
在 System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(对象 实例,Object[] 输入,Object[]& 输出)
在 System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
在 System.ServiceModel.Dispatcher.MessageRpc.Process(布尔 isOperationContextSet)

错误提到了我的“Users”表,它基本上有 3 列:Id / Name / Deleted,表之间存在一些关系,并且我的所有表都有“Id”作为主键 ID。

知道为什么我会收到此错误吗?

非常感谢。

【问题讨论】:

  • 我刚刚通过向每个实体类添加部分类来传递此错误:[DataServiceKey("Id")]。它似乎区分大小写。但现在我有一个不同的错误:The exception message is 'The property 'Columns' on type 'OData.Data.User' is not a valid property. 这个“列”是由 SubSonic 生成的,代码如下: public IList Columns{ get{ return tbl.Columns;我需要做什么来解决这个问题?谢谢。

标签: asp.net wcf asp.net-mvc-2 wcf-data-services odata


【解决方案1】:

您应该能够在您的实体类上添加 [IgnoreProperties("Columns")] 属性,这将从 WCF 数据服务运行时隐藏 Columns 属性。否则运行时不支持 T 不是实体类型的 IList 类型的属性。

【讨论】:

    猜你喜欢
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2011-11-20
    相关资源
    最近更新 更多