Linq 从整数列表中选择多个 ID(主键)
我有一个整数列表,
''# VB
Dim ResultIDsas List(Of Integer) = new List(Of Integer)
// C#
List<int> ResultIDs= new List<int>();
通过循环 Lucene Read 的结果将其添加到该列表中。
''#VB
While (i <= (page * 10) AndAlso i < HitCollection.Length)
Dim document As Document = HitCollection.Doc(i)
Dim _event As New Domain.[Event]
ResultIDs.Add(document.[Get]("ID"))
i += 1
End While
// C#
while ((i <= (page * 10) && i < HitCollection.Length)) {
Document document = HitCollection.Doc(i);
Domain.Event _event = new Domain.Event();
ResultIDs.Add(document.Get("ID"));
i += 1;
}
现在问题来了。
假设我的整数列表是 [1,5,6,19,22]
当我需要查询我的服务时,linq (lambda) 表达式会是什么样子?
''# VB
EventService.QueryEvents().Where(Function(e) (e.ID = 1))
// C#
EventService.QueryEvents().Where((System.Object e) => (e.ID == 1));
// Obviously these will simply grab ID of "1" which is not what we want.
I have an integer list
''# VB
Dim ResultIDsas List(Of Integer) = new List(Of Integer)
// C#
List<int> ResultIDs= new List<int>();
I add to that list by looping through the results of a Lucene Read.
''#VB
While (i <= (page * 10) AndAlso i < HitCollection.Length)
Dim document As Document = HitCollection.Doc(i)
Dim _event As New Domain.[Event]
ResultIDs.Add(document.[Get]("ID"))
i += 1
End While
// C#
while ((i <= (page * 10) && i < HitCollection.Length)) {
Document document = HitCollection.Doc(i);
Domain.Event _event = new Domain.Event();
ResultIDs.Add(document.Get("ID"));
i += 1;
}
Now here's where the question comes in.
Say my List of Integers is [1,5,6,19,22]
What would a linq (lambda) expresion look like when I need to query my service?
''# VB
EventService.QueryEvents().Where(Function(e) (e.ID = 1))
// C#
EventService.QueryEvents().Where((System.Object e) => (e.ID == 1));
// Obviously these will simply grab ID of "1" which is not what we want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将生成相当于 SELECT ... WHERE e.ID in (1,5,...)
this would generate the equivalent of SELECT ... WHERE e.ID in (1,5,...)
我在这里猜测,但这似乎就是你所追求的。
在 C# 中:
I'm taking a guess here, but this seems to be what you're after.
And in C#: