OData“列表中的 ID"询问 [英] OData "where ID in list" query
问题描述
我有一个 OData 服务,我正在尝试按 ID 列表进行过滤;SQL 等效项类似于:
I have an OData service where I'm trying to filter by a list of IDs; the SQL equivalent would be something like:
SELECT * FROM MyTable WHERE TableId IN (100, 200, 300, 400)
我尝试过滤的属性类型为 Int32.我尝试了以下操作,这给了我一个错误Operator 'add' 与操作数类型 'Edm.String' 和 'Edm.Int32' 不兼容":
The property I'm trying to filter on is typed as an Int32. I've tried the following, which gives me an error "Operator 'add' incompatible with operand types 'Edm.String' and 'Edm.Int32'":
string ids = ",100,200,300,400,";
from m in provider.Media where ids.Contains("," + t.media_id + ",")
以及
string ids = ",100,200,300,400,";
from m in provider.Media where ids.Contains("," + t.media_id.ToString() + ",")
和
string ids = ",100,200,300,400,";
from m in provider.Media where ids.Contains("," + Convert.ToString(t.media_id) + ",")
和
string ids = ",100,200,300,400,";
from m in provider.Media where ids.Contains(string.Concat(",", t.media_id, ","))
如您所见,目前我正在使用 LINQ 来查询服务.
As you can see, currently I'm using LINQ to query the service.
有什么方法可以做我想做的事情,还是我一直在构建文本过滤器并使用 AddQueryOption,然后遍历列表并手动添加或 media_id eq 100"子句?
Is there a way I can do what I'm trying to, or am I stuck constructing a text filter and using AddQueryOption, and iterating through the list and manually adding "or media_id eq 100" clauses?
推荐答案
With OData 4.01,in
语句支持如下:
With OData 4.01, in
statement is supported like this:
http://host/service/Products?$filter=Name in ('Milk', 'Cheese')
这篇关于OData“列表中的 ID"询问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!