DynamicQueryable 如何支持数组运算符?
我一直在使用 Scott Guthrie 的 博客文章。
该文档有一个支持的运算符表。主要运算符之一如下:
x[…] 数组或索引器访问。不支持多维数组。
但是,我不知道如何使用它。
我没想到以下任何一个都会起作用,事实上它们也不起作用。
var ctx = new MyDbContext();
var parameters = new Object[] { new int[] { 1, 2, 3 } };
var qry = ctx.Set<User>().Where<User>("it.Id in @0", parameters);
var qry = ctx.Set<User>().Where<User>("it.Id.In(@0)", parameters);
var qry = ctx.Set<User>().Where<User>("it.Id = @0", parameters);
var qry = ctx.Set<User>().Where<User>("@0.Contains(it.Id)", parameters);
它基本上是一个 In 查询,但我不知道如何表达它。
I have been using the DynamicQueryable Linq extensions featured in Scott Guthrie's blog post.
The documentation has a table of supported operators. One of the primary operators is the following:
x[…]
Array or indexer access. Multi-dimensional arrays are not supported.
However, I cannot figure out how it can be used.
I didn't expect any of the following to work and in fact they don't.
var ctx = new MyDbContext();
var parameters = new Object[] { new int[] { 1, 2, 3 } };
var qry = ctx.Set<User>().Where<User>("it.Id in @0", parameters);
var qry = ctx.Set<User>().Where<User>("it.Id.In(@0)", parameters);
var qry = ctx.Set<User>().Where<User>("it.Id = @0", parameters);
var qry = ctx.Set<User>().Where<User>("@0.Contains(it.Id)", parameters);
It is basically an In query, but I am not sure how to express it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这或许是一个误会。意思是可以查询特定索引位置处的集合元素。例如:
然后您可以通过以下方式查询第三个 OrderDetail 中具有详细描述“Bicycle”的所有订单:
我认为出于您的目的,您需要建立一个“OR”链
"it.Id == 1 或it.Id == 2 或 it.Id == 3"
(或在循环中动态构建此查询字符串),Where 方法中不带参数。This is perhaps a misunderstanding. Meant is that it is possible to query for collection elements at a specific index position. For example:
Then you can query for all orders which have the Detail description "Bicycle" in the third OrderDetail by:
I think for your purpose you need to build up an "OR" chain
"it.Id == 1 or it.Id == 2 or it.Id == 3"
(or build this query string dynamically in a loop) without parameters in the Where method.