如何使用odata获取参考数据

时间:2021-03-22 21:04:48

I have two tables, NetworkAccount and Division. The are related by DivisionID NetworkAccount has the full user information including a DivisionID Division has all related information related to a division.

我有两个表,NetworkAccount和Division。与DivisionID NetworkAccount相关的完整用户信息包括DivisionID Division具有与分部相关的所有相关信息。

I have the users logon name, how can I retrive his DivisionName which is stored in the Division table. I want to do this with one query to the oData service.

我有用户登录名,如何检索存储在Division表中的DivisionName。我想通过对oData服务的一个查询来执行此操作。

I've tried the following and nothing is giving me the answer I wanted.

我尝试了以下内容,没有什么能给我我想要的答案。

http://localhost:54471/NetworkInfo.svc/Divisions?$filter=Username eq 'test\name'

http:// localhost:54471 / NetworkInfo.svc / Divisions?$ filter =用户名eq'test'名称'

I get the following

我得到以下内容

<message xml:lang="en-CA">No property 'Username' exists in type 'NetworkInfoService.Division' at position 0.</message>

http://localhost:54471/NetworkInfo.svc/Divisions?$filter=NetworkAccount/Username eq 'test\name' I get the following

http:// localhost:54471 / NetworkInfo.svc / Divisions?$ filter = NetworkAccount / Username eq'test \ name'我得到以下内容

<message xml:lang="en-CA">No property 'NetworkAccount' exists in type 'NetworkInfoService.Division' at position 0.</message>

But if I do the opposite, if I want to get users that belong to a certain division, it works no problem, see below.

但是,如果我做相反的事情,如果我想获得属于某个部门的用户,那么它没有问题,请参阅下文。

localhost:54471/NetworkInfo.svc/NetworkAccounts?$filter=Division/Name eq 'SomeName'

localhost:54471 / NetworkInfo.svc / NetworkAccounts?$ filter = Division / Name eq'TomeName'

Any help would be much appreciated. Thanks

任何帮助将非常感激。谢谢

2 个解决方案

#1


0  

Could you please post the shape of the model for the Division and NetworkAccount types? The typical way to do this in OData is a query like: /NetworkAccounts(TheIDOfTheUserImLookingFor)/Division

你能否为Division和NetworkAccount类型发布模型的形状?在OData中执行此操作的典型方法是查询,如:/ NetworkAccounts(TheIDOfTheUserImLookingFor)/ Division

#2


0  

Ok, I figured out the syntax... it goes like this:

好的,我想出了语法......它是这样的:

http://localhost:12345/NetworkInfo.svc/NetworkAccounts?$filter=Username eq 'test\name'&$expand=Division

The $expand keyword is the trick.

$ expand关键字就是诀窍。

#1


0  

Could you please post the shape of the model for the Division and NetworkAccount types? The typical way to do this in OData is a query like: /NetworkAccounts(TheIDOfTheUserImLookingFor)/Division

你能否为Division和NetworkAccount类型发布模型的形状?在OData中执行此操作的典型方法是查询,如:/ NetworkAccounts(TheIDOfTheUserImLookingFor)/ Division

#2


0  

Ok, I figured out the syntax... it goes like this:

好的,我想出了语法......它是这样的:

http://localhost:12345/NetworkInfo.svc/NetworkAccounts?$filter=Username eq 'test\name'&$expand=Division

The $expand keyword is the trick.

$ expand关键字就是诀窍。