asp.net - 具有Subsonic 3的OData(WCF数据服务)

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

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

然后,我在ASP.NET MVC项目中创建一个新的WCF数据服务项,称为“ service.svc”,它指向由Subsonic生成的“ TestDB”上下文,该上下文是从“ OData”项目获得的。我已根据本文在“服务”类中添加了此属性: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(IDictionary 2 knownTypes, IDictionary 2 childTypes,
IDictionary 2 entitySets)
at System.Data.Services.Providers.BaseServiceProvider.PopulateMetadata()
at System.Data.Services.DataService
1.CreateProvider()
在System.Data.Services.DataService 1.HandleRequest()
at System.Data.Services.DataService
1.ProcessRequestForMessage(Stream
邮件正文)
在SyncInvokeProcessRequestForMessage(Object,Object [],Object [])
在System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
实例,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(Boolean
isOperationContextSet)


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

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

非常感谢你。

最佳答案

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

关于asp.net - 具有Subsonic 3的OData(WCF数据服务),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3643652/

相关文章:

android - 在浏览器中工作的本地主机上的 WCF 服务在 PhoneGap 中不工作

c# - 为什么 WCF 异步方法中有 Response 返回类型?

mysql - 用于 Windows Phone 远程数据库的 VB silverlight

c# - 如何从自定义异常过滤器返回 JSON 结果?

asp.net - Entity Framework 和 Oracle - 如何插入 ID?

javascript - jQuery.validate 不适用于 ASP.NET Core

c# - 在 .net 中读/写雅虎日历(测试版)

c# - 无法在 Entity Framework 中创建类型为 'System.Object' 的常量值

asp.net-mvc-2 - 如何仅使用 DataAnnotations 验证 Viewmodel 中的部分字段?

asp.net-mvc-2 - AuthorizeAttribute MVC 2 中的 IoC Unity 容器注入(inject)