Is there a way to write an ODATA query (i.e., using an ODATA URL) that tests for the existance of a relationship between two entity instances?
Imagine I have two entity types in an ODATA service: Person and Project. Imagine I've defined a many-to-many relationhip between them (something like Person owns Project). I have the primary key (ID) of each开发者_JS百科 of a Person and a Project and want to know if the Person owns the Project.
I can figure out, given a Person, how to get all the Projects owned by that person but this will, in the general case, return way more data than I want (and have perf problems in other similar scenarios). Can I query for the relationship itself somehow?
My server is using WCF and Entity Framework 4.0 on ASP.NET. My client is HTML and jquery running in a browser.
If there's no way to write the relationship query, is there a best practice for something like this to extend the ODATA service with a custom method to test this?
Thanks!
David
I think you can simply call something like: ODataService.svc/Persons(1)/Projects(5)
. This will try to return Project
with Id=5 related to Person
with Id=2 because Persons
in this case is the entity set and Projects
is the navigation property on the Person
entity. If the relation exists you will get the record. If it doesn't exists you will get something like Resource not found.
精彩评论