I'm trying to use WCF Data Service with Subsonic, but ran into this error when I try to access my "service.svc". I have 2 projects, one is a class library (called "OData") that has Subsonic t4 templates to generate the classes for my table. Another is an ASP.NET MVC2 project that references to the "OData" project.
I then create a new WCF Data Service item inside my ASP.NET MVC project, called "service.svc", points to my "TestDB" context generated by Subsonic that I got from the "OData" project. I've add this attribute on my "service" class per this article: http://theruntime.com/blogs/jaykimble/archive/2008/11/18/quotsubsonicquot-for-services-found-subsonic-3--ado.net-data-services.aspx
This is how my service class looks like:
[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;
}
}
When I try to access my http://localhost/Service.svc, I receive this error:
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
at System.Data.Services.DataService2 knownTypes, IDictionary
2 childTypes, IDictionary2 entitySets) at System.Data.Services.Providers.BaseServiceProvider.PopulateMetadata() at System.Data.Services.DataService
1.CreateProvider()1.HandleRequest() at System.Dat开发者_StackOverflow社区a.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)
The error mentions about my "Users" table, which basically has 3 columns: Id / Name / Deleted, there are some relationship between tables, and all my table has "Id" as the Primary key ID.
Any idea why I'm receiving this error?
Thank you very much.
You should be able to add [IgnoreProperties("Columns")] attribute on your entity class which will hide the Columns properties from the WCF Data Service runtime. Cause otherwise the runtime doesn't support properties of type IList where T is not an entity type.
精彩评论