Data Platform Developer Center >
Data Platform Development Forums
>
WCF Data Services (formerly known as ADO.NET Data Services)
>
Nullable Foreign Keys
Nullable Foreign Keys
- Hi there,
We've got the following (for explanatory reasons simplified) situation. There is an Order table and an Items table and between those there's a foreign key relationship defined. The foreign key column on the Item table does allow null values so Items may exist without an Order. Creating this relationship:
Order 0..1 --<> * Item
For example, there are 2 Items in the database, one belonging to an Order and another one standing on its own (i.e. has a null value in the foreign key column). Now when i do a request for the one belonging to an Order like this:
http://localhost:4717/WebDataService1.svc/Items(1)/Orders
I get the parent Order as result back from the service which is logical as there is a valid foreign key relationship. Now when i do a request for the unrelated Item like this:
http://localhost:4717/WebDataService1.svc/Items(2)/Orders
I won't get a response at all. The server returns just nothing, like it is hanging. Shouldn't the server at least return something? Like when you query for Items for an Order which has none you at least get an empty result back which you can handle in your application...just hanging there seems so useless ;-)
I hope i'm clear enough
Note: This a readonly DataService
Thanks,
E- Edited byEllen_B Monday, October 26, 2009 3:50 PMadded note
Answers
- When a reference navigation property is null, the server returns status code (204) - which means No Content. And the payload is empty. Since this is a reference property, there is nothing else we can return in the payload. For collection navigation properties, we do return a empty collection.
Hope this helps.
Thanks
Pratik
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byPratik Patel - MSFTModeratorFriday, October 30, 2009 4:15 PM
All Replies
- When a reference navigation property is null, the server returns status code (204) - which means No Content. And the payload is empty. Since this is a reference property, there is nothing else we can return in the payload. For collection navigation properties, we do return a empty collection.
Hope this helps.
Thanks
Pratik
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byPratik Patel - MSFTModeratorFriday, October 30, 2009 4:15 PM
- Understood,
Thanks Pratik, for clearing it up
Greetings,
E


