locked
Exception : there is a top IQueryable property 'Data' whose element type is not an entity type. RRS feed

  • Question

  • I got following error when I tried to run my dataservice. I looked at few other blogs for sugeestions/fixes. Most of them recommended to decorate your Entity with DataServiceKeyattribute. Even after applying the attribute I 'm unable to get rid of the error. I have pasted my entire Error Info and Code .

    Any thoughts?

    Error:

    The server encountered an error processing the request. The exception message is 'On data context type 'ProjectDataContext', there is a top IQueryable property 'Data' 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 entitySets) at System.Data.Services.Providers.BaseServiceProvider.PopulateMetadata() at System.Data.Services.DataService`1.CreateProvider(Type dataServiceType, Object dataSourceInstance, DataServiceConfiguration& configuration) at System.Data.Services.DataService`1.EnsureProviderAndConfigForRequest() 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.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)



    Code :


    [System.Data.Services.Common.

    DataServiceKey("ID")]

     

    public class ProjectData

    {

     

    public string ProjectDataID;

     

    public string ProjectName;

    }

     

     

    public class ProjectDataContext

    {

     

    List<ProjectData> data;

     

    public ProjectDataContext()

    {

    data =

    new List<ProjectData> { new ProjectData() { ProjectDataID = "1", ProjectName = "Test" } };

    }

     

    public IQueryable<ProjectData> Data

    {

     

    get

    {

     

    return data.AsQueryable<ProjectData>();

    }

    }

    }

    [System.ServiceModel.

    ServiceBehavior(IncludeExceptionDetailInFaults = true)]

     

    public class NonRelDBService : DataService<ProjectDataContext>

    {

     

     

    // This method is called only once to initialize service-wide policies.

     

    public static void InitializeService(IDataServiceConfiguration config)

    {

     

    // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.

     

    // Examples:

    config.SetEntitySetAccessRule(

    "ProjectData", EntitySetRights.AllRead);

     

    // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);

    }

     

    }

    Sunday, May 3, 2009 7:31 PM

Answers

  • Your entity set is called Data:

    public IQueryable<ProjectData> Data

    so:

    config.SetEntitySetAccessRule("Data", EntitySetRights.AllRead);

    Regards,

    PQ
    Peter Q. http://blogs.msdn.com/peter_qian
    Monday, May 4, 2009 3:25 AM
    Answerer

All replies

  • Hi,

    The string you give to the DataServiceKey attribute needs to match the name of the ID property on your entity type.

    That said, I think the code for ProjectData class definition should look more like:


        [DataServiceKey("ProjectDataID")]
        public class ProjectData
        {
            public string ProjectDataID
            {
                get;
                set;
            }
    
            public string ProjectName
            {
                get;
                set;
            }
        }


    Can you give that a shot and see if the error goes away?
    Matt Meehan, ADO.NET Data Services (Astoria)
    Sunday, May 3, 2009 10:57 PM
    Moderator
  • Thankk Matt,

    I redefined my ProjectData class as you suggested and it fixed that exception. But Now I'm getting different exception

    Error:

    The server encountered an error processing the request. The exception message is 'Exception has been thrown by the target of an invocation.'. See server logs for more details. The exception stack trace is:

    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Data.Services.DataServiceConfiguration.InvokeStaticInitialization(Type type) at System.Data.Services.DataService`1.CreateConfiguration(Type dataServiceType, IDataServiceProvider provider, Object dataSourceInstance) at System.Data.Services.DataService`1.CreateProvider(Type dataServiceType, Object dataSourceInstance, DataServiceConfiguration& configuration) at System.Data.Services.DataService`1.EnsureProviderAndConfigForRequest() 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.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

    Code :

    [System.Data.Services.Common.DataServiceKey("ProjectDataID")]
    
    public class ProjectData
    
    {
    
    public string ProjectDataID
    
    {
    
    get;
    
    set;
    
    }
    
    public string ProjectName
    
    {
    
    get;
    
    set;
    
    }
    
    }
    
    
    public class ProjectDataContext
    
    {
    
    List<ProjectData> data;
    
    public ProjectDataContext()
    
    {
    
    data = new List<ProjectData> { new ProjectData() { ProjectDataID = "1", ProjectName = "Test" } };
    
    }
    
    public IQueryable<ProjectData> Data
    
    {
    
    get
    
    { 
    
    return data.AsQueryable<ProjectData>();
    
    }
    
    }
    
    }
    
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    
    public class NonRelDBService : DataService<ProjectDataContext>
    
    {
    
    
    // This method is called only once to initialize service-wide policies.
    
    public static void InitializeService(IDataServiceConfiguration config)
    
    {
    
    // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
    
    // Examples:
    
    config.SetEntitySetAccessRule("ProjectData", EntitySetRights.AllRead);
    
    // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
    
    }
    
    
    }
    

    Monday, May 4, 2009 1:02 AM
  • Your entity set is called Data:

    public IQueryable<ProjectData> Data

    so:

    config.SetEntitySetAccessRule("Data", EntitySetRights.AllRead);

    Regards,

    PQ
    Peter Q. http://blogs.msdn.com/peter_qian
    Monday, May 4, 2009 3:25 AM
    Answerer
  • Oops..Good catch.
    Monday, May 4, 2009 11:48 AM