2010-09-04 62 views
3

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

然后,我在我的ASP.NET MVC项目中创建一个名为“service.svc”的新WCF数据服务项,指向由Subsonic生成的“OData”项目生成的“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,我收到此错误:关于我的“用户”表,基本上有3列

Request Error

The server encountered an error processing the request.
The exception message is 'On data context type 'SymetraGivingDB', there is a top IQueryable property 'Users' whose element type is not an entity type.
Make sure that the IQueryable property is of entity type or specify the IgnoreProperties attribute on the data context type to ignore this property.'. See server logs for more details. The exception stack trace is:

at 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()
at System.Data.Services.DataService 1.HandleRequest()
at System.Data.Services.DataService
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.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

的错误中提到:ID /姓名/删除,有表有一定的关系,和我所有的表有“ID”作为主键ID。

任何想法为什么我收到此错误?

非常感谢。

+0

我刚刚通过向每个实体类添加分部类来传递此错误:'[DataServiceKey(“Id”)]'。看起来它是区分大小写的。但是现在我有一个不同的错误: '异常信息是''OData.Data.User'类型'属性'列'不是一个有效的属性。' 这个“列”是由SubSonic生成的,代码如下: public IList 列获得{ 返回tbl.Columns; } } 我需要做些什么来解决这个问题?谢谢。 – Saxman 2010-09-04 19:39:47

回答

1

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