Odata 通过将具体实体定义为操作数进行筛选,即不使用原语值

Odata 通过将具体实体定义为操作数进行筛选,即不使用原语值,odata,Odata,在我检查过的示例中,操作数始终是一个基本值,如: http://host/service/Products?$filter=MainIngredient eq 'Milk' 如果mainComponent属性是一个实体,并且我想精确引用该实体,该怎么办?抽象出其他的情况,这将是类似的 http://host/service/Products?$filter=MainIngredient eq Ingredient('770d5720-9ae8-11e3-a5e2-0800200c9a66)

在我检查过的示例中,操作数始终是一个基本值,如:

http://host/service/Products?$filter=MainIngredient eq 'Milk'
如果
mainComponent
属性是一个实体,并且我想精确引用该实体,该怎么办?抽象出其他的情况,这将是类似的

http://host/service/Products?$filter=MainIngredient eq Ingredient('770d5720-9ae8-11e3-a5e2-0800200c9a66)

…或者过滤器根本不是要使用的正确工具吗?

我认为您的意思是MainComponent是指向Component类型的单个实体的导航属性的名称,例如:

http://host/service/Products(1234)/MainIngredient
如果是这种情况,并且假设成分的键被称为“ID”,那么我认为URL的正确形式是:

http://host/service/Products?$filter=MainIngredient/ID eq guid'770d5720-9ae8-11e3-a5e2-0800200c9a66'

这将只返回通过MainComponent链接到您在问题中提供的ID的成分的产品。

我担心这是一种方法,但是我不太喜欢处理/公开identity属性(
guid
),但是。。。