如何使用VB.NET和LINQ附加"where"子句? [英] How do I append a 'where' clause using VB.NET and LINQ?
问题描述
我刚接触VB.NET,在这里遇到了一些麻烦,我认为应该很简单.
I am pretty new to VB.NET and am having a bit of trouble here with something I thought should be simple.
简单起见,假设我有一个要搜索名称"的文档表(实际上还有其他几个表,联接等..).我需要能够根据传入的字符串值使用where
子句来构建查询.
Keeping it simple, let's say I have a Document table with "Name" that I want to search on (in reality there are several other tables, joins, etc. ..). I need to be able to build the query using a where
clause based on string values passed in.
示例-用户可以输入"ABC","ABC DEF","ABC DEF GHI".
Example - the user may pass in "ABC", "ABC DEF", "ABC DEF GHI".
最终查询将是(我知道语法不正确):
The final query would be (the syntax is not correct, I know):
Select * from Documents Where Name Like %ABC% AND Name Like %DEF% AND Name like %GHI%
所以,我认为我可以做这样的事情.
So, I thought I could do something like this.
Dim query = From document In _context.Documents
<< loop based on number of strings passed in >>
query = query.Where( ... what goes here?? )
由于某种原因,由于脑力衰竭或某种原因,我无法弄清楚如何在VB.NET中实现此功能,或者我做得是否正确.
For some reason, being brain-dead or something, I can't figure out how to make this work in VB.NET, or if I'm doing it correctly.
推荐答案
我相信这是您在VB中的做法(我是C#开发人员):
I believe this is how you would do it in VB (I'm a C# developer):
query = query.where(Function(s) s = "ABC")
请参见 LINQ-示例查询 对于某些示例.
See LINQ - Sample Queries for some examples.
这篇关于如何使用VB.NET和LINQ附加"where"子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!