Friday, June 25, 2010

OData: Using the reflection based provider

If you start implementing WCF Data Services, sooner or later you will certainly see following error when calling the OData feed:

“On data context type 'XXXXX’, there is a top IQueryable property 'XXXX' 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.”

This can mean two things. Either you have a property that cannot be processed by the Entity Data Model used by OData or OData could not find a primary key for your class.

OData requires a primary key for every resource. If you use the reflection based provider, it uses one of the following mechanisms to find the primary key:

  • via the [DataServiceKey] attribute
  • by looking for a "FooID" property, where the type is called "Foo"
  • by looking for an "ID" property

Important to know is that this convention is case-sensitive: "FooId" won't work without a [DataServiceKey].


Peter said...

So can we conclude that NHibernate components are not compatible with WCF Data Services?

Ikutsin said...

I strongly believe that NHibernate and OData service can live together.

I recently reused ExpressionSerializer pass queries through WCF or other pipes. But this approach can not be used in production maybe only for intranet.
As for OData, it has it's own security system and not exposed for injections.

Bart Wullems said...

There are some ways to get it working(especially in readonly mode). If you want more info, contact me.