开发者

How do I query using ODATA for the existence of a relationship between two entities?

开发者 https://www.devze.com 2023-02-21 14:00 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号