I checked the code example at http://msdn.microsoft.com/en-us/library/dd728281.aspx#Y0, and found one interesting thing: if we remove Public ReadOnly Property Items() from OrderItemData class, the service shows an error. Even if we don’t try to access Items, and only working with Orders.
Can somebody explain why this property is needed?
EDIT: To clarify: the property isn’t used directly. I removed it from the code, it compiles successfully, but service returns Request error: “The server encountered an error processing the request. See server logs for more details.” And there is no exception thrown.
I think that the service for some reason might need IQueryable(Of Item) property. Even if the property returns Nothing, the service starts working again:
Public ReadOnly Property Items() As IQueryable(Of Item)
Get
Return Nothing
End Get
End Property
When WCF Data Service uses reflection provider (which is what the sample does), each entity type has to fulfill these conditions:
If you remove the Items property you violate the rule number 3 above. As such the type Item is not recognized as an entity type anymore (it is internally treated as a complex type), but then it’s used on the Order class as an item type for a collection. That means it would have to be a navigation property, but that requires the item type to be an entity.
If you’re looking for some kind of containment (where the Items are only accessible through the Order they belong to), the WCF DS current doesn’t support this yet.