如何使用 ODATA 查询两个实体之间是否存在关系?
有没有办法编写 ODATA 查询(即使用 ODATA URL)来测试两个实体实例之间是否存在关系?
想象一下,我的 ODATA 服务中有两种实体类型:人员和项目。想象一下,我已经定义了它们之间的多对多关系(类似于“人拥有项目”)。我有一个人和一个项目的主键 (ID),并且想知道该人是否拥有该项目。
我可以弄清楚,给定一个人,如何获取该人拥有的所有项目,但这在一般情况下会返回比我想要的更多的数据(并且在其他类似场景中会出现性能问题)。我可以以某种方式查询关系本身吗?
我的服务器在 ASP.NET 上使用 WCF 和 Entity Framework 4.0。我的客户端是在浏览器中运行的 HTML 和 jquery。
如果无法编写关系查询,是否有类似的最佳实践来使用自定义方法扩展 ODATA 服务来测试它?
谢谢!
大卫
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以简单地调用以下内容:
ODataService.svc/Persons(1)/Projects(5)
。这将尝试返回 Id=5 的Project
与 Id=2 的Person
相关,因为在本例中Persons
是实体集,并且Projects
是Person
实体上的导航属性。如果关系存在,您将获得记录。如果它不存在,您将得到类似找不到资源的信息。I think you can simply call something like:
ODataService.svc/Persons(1)/Projects(5)
. This will try to returnProject
with Id=5 related toPerson
with Id=2 becausePersons
in this case is the entity set andProjects
is the navigation property on thePerson
entity. If the relation exists you will get the record. If it doesn't exists you will get something like Resource not found.