locked
ADO.NET data services RRS feed

  • Question

  • hi all,

    i tried to play around with ADO.NET data services. i create a web site project, after that i created a "Link to SQL classes" item (my database that contains Contact table) and a "ADO.NET data service" new item (my data service). everything compiles great but at run time i got this error message. i looked how my Contact class is generated and it has one of the properties marked as primary key. i saw an earlier post that was talking about decorating one of the properties with DataServiceKey/DataKey attribute... but i can not find this attribute class anywhere.

    what do i miss here? any help will be apreciated.

    The server encountered an error processing the request. The exception message is 'On data context type 'MyDBDataContext', there is a top IQueryable property Contacts' 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)

    Friday, August 15, 2008 2:29 AM

Answers

  •  

    I think most of the problems you're seeing stem from the fact that ADO.NET Data Services talk in terms of conceptual entities, and so borrows most of the terminology and expressiveness from the ADO.NET Entity Framework.

     

    So, for example, the list of 'primitive types' correspond to the EDM Simple Types (http://msdn.microsoft.com/en-us/library/bb399213.aspx), and are mapped to CLR types as specified on http://msdn.microsoft.com/en-us/library/cc668779.aspx. System.Char isn't supported, so while there is nothing wrong with the property per se, it can't be mapped to an EDM type.

     

    Primitive types can be 'grouped' into complex types or entity types. The difference between an entity type and a complex type is that an entity type has one or more properties that form a key or identifier for each instance, and they have at least one entity set (top-level IQueryable) in which they can be found.

     

    The most straightforward fix would seem to try to map Property1 to a string type. Please let us know if this can't work for you.

     

    Saturday, August 16, 2008 7:05 PM

All replies

  • The Primary key attribute goes on the class which you want to expose as an entity set via your service. You can read about it here

    http://msdn.microsoft.com/en-us/library/system.data.services.common.dataservicekeyattribute.aspx

    Friday, August 15, 2008 2:38 AM
    Moderator
  •  

    thanks but how come i couldn't find DataServiceKeyAttribute?

    i installed SP1 VS and .net 3.5 ...

    i'll double check and get back to you.

     

    Friday, August 15, 2008 5:12 AM
  • Its in the System.Data.Services.Common namespace available in the System.Data.Services.Client.dll

    You will have to add a reference to the System.Data.Services.Client.dll in the project with the data service.

     

    Friday, August 15, 2008 6:24 AM
    Moderator
  • I'm suffering the same thing.

    S
    eems rather strange to have to use DataServiceKey when LINQ already marks the primary keys.

    --
    Rory

    Friday, August 15, 2008 12:30 PM
  • searching for this attribute on msdn it doesn't pop up any urls... it seems it wasn't indexed properly.
    Friday, August 15, 2008 5:13 PM
  • so it worked for you? i added that attribute to the entity class and i get the same error...
    Friday, August 15, 2008 5:22 PM
  • thx mike, unfortunately using this attribute doesn't suffice, i get the same exact exception. can you please help to get through with this? thanks!
    Friday, August 15, 2008 6:05 PM
  • ok, i re-created the project, trying so many things i though maybe i screwed up something...
    anyhow, now i have below error.

    The server encountered an error processing the request. The exception message is 'The property 'Property1' on type 'TTT_DATA' is not a valid property.
    Make sure that the type of the property is a public type and a supported primitive type or a entity type with a valid key or a complex type.'.
    See server logs for more details.

    The exception stack trace is:
    at System.Data.Services.Providers.ReflectionServiceProvider.BuildTypeProperties(ResourceType parentResourceType, IDictionary`2 knownTypes, Queue`1 unvisitedTypes, IEnumerable`1 entitySets) at System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadataForTypes(IDictionary`2 knownTypes, Queue`1 unvisitedTypes, IEnumerable`1 entitySets) 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)

    the type the error is talking about is:

        private System.Nullable<char> _Property1;

        [Column(Storage="_Property1", DbType="NVarChar(1)")]
        public System.Nullable<char> Property1
        {
            get
            {
                return this._Property1;
            }
            set
            {
                if ((this._Property1 != value))
                {
                    this.OnProperty1Changing(value);
                    this.SendPropertyChanging();
                    this._Property1 = value;
                    this.SendPropertyChanged("Property1");
                    this.OnProperty1Changed();
                }
            }
        }

    1) what is wrong with this generated property?
    2) what are the supported primitive types and entity types?
    3) why the property is not generated with CanBeNull=true attribute since it is nullable?

    are all these issues bugs? did you actually ship with all these problems?...


    Friday, August 15, 2008 6:21 PM
  •  

    I think most of the problems you're seeing stem from the fact that ADO.NET Data Services talk in terms of conceptual entities, and so borrows most of the terminology and expressiveness from the ADO.NET Entity Framework.

     

    So, for example, the list of 'primitive types' correspond to the EDM Simple Types (http://msdn.microsoft.com/en-us/library/bb399213.aspx), and are mapped to CLR types as specified on http://msdn.microsoft.com/en-us/library/cc668779.aspx. System.Char isn't supported, so while there is nothing wrong with the property per se, it can't be mapped to an EDM type.

     

    Primitive types can be 'grouped' into complex types or entity types. The difference between an entity type and a complex type is that an entity type has one or more properties that form a key or identifier for each instance, and they have at least one entity set (top-level IQueryable) in which they can be found.

     

    The most straightforward fix would seem to try to map Property1 to a string type. Please let us know if this can't work for you.

     

    Saturday, August 16, 2008 7:05 PM
  • it is not clear what are the mappings between the sql types and clr types/EDM types...

    to make it work i had to
    1) make sure i have a primary key defined on the table
    2) use the DataServiceKey attribute on that column which is the primary key


    Monday, August 18, 2008 6:02 PM
  • thankx problem solved by including namespaces System.Data.Services.Common and System.Data.Services.Client
    • Proposed as answer by sshikha Tuesday, July 7, 2009 7:01 AM
    Tuesday, July 7, 2009 7:00 AM