3

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

然后,我在我的 ASP.NET MVC 项目中创建一个新的 WCF 数据服务项,名为“service.svc”,指向我从“OData”项目中获得的由 Subsonic 生成的“TestDB”上下文。根据这篇文章,我已经在我的“服务”类中添加了这个属性:http: //therruntime.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, IDictionary2 childTypes, IDictionary 1.CreateProvider () 在 System.Data.Services.DataService 1.ProcessRequestForMessage(Stream messageBody) 在 SyncInvokeProcessRequestForMessage(Object, Object[] , Object[] ) 在 System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) 在 System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41 (MessageRpc& rpc)处的 (MessageRpc& rpc)2 entitySets)
at System.Data.Services.Providers.BaseServiceProvider.PopulateMetadata()
at System.Data.Services.DataService

1.HandleRequest()
at System.Data.Services.DataService






在 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 / Deleted,表之间存在一些关系,并且我的所有表都有“Id”作为主键 ID。

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

非常感谢你。

4

1 回答 1

1

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

于 2010-09-16T12:04:55.163 回答