[英]linq to dataset equivalent of SQL LIKE clause
What is the linq equivalent of a SQL clause like WHERE UserName LIKE 'fr_d'
? SQL子句(如WHERE UserName LIKE 'fr_d'
)的linq等效项是什么?
I'm working with a dataset in memory rather than a SQL database so I don't think I can use something like where SqlMethods.Like(p.UserName, "Fr_d")
我正在使用内存中的数据集而不是SQL数据库,所以我认为我无法使用像where SqlMethods.Like(p.UserName, "Fr_d")
(Not that my installation of VS2008 is admitting that SqlMethods or even System.Data.Linq.SqlClient exist at the moment, but thats a whole different problem!) (并不是说我的VS2008安装程序承认目前存在SqlMethods甚至System.Data.Linq.SqlClient,但这就是一个完全不同的问题!)
Like this: 像这样:
table.Where(row => row.StringColumn.StartsWith("prefix"))
(You may also want to call Contains
or EndsWith
) (您可能还想调用Contains
或EndsWith
)
EDIT : In your case, you want 编辑 :在您的情况下,您想要
table.Where(p => p.UserName.StartsWith("Fr") && p.UserName.EndsWith("d") && p.UserName.Length == 4)
Alternatively, you can also put a regex inside the Where
clause. 另外,您也可以将正则表达式放在Where
子句中。
If you do, make sure to create the RegEx
object outside the Where
call so that it doesn't get parsed for each row. 如果这样做,请确保在Where
调用之外创建RegEx
对象,以免对每一行都进行解析。
I belive this is what you really want. 我相信这就是您真正想要的。 It will allow Fr{ any one character }d: 它将允许Fr { 任何一个字符 } d:
table.Where(p => p.UserName.StartsWith("Fr") && p.UserName.EndsWith("d") && p.UserName.Length == 4 )
Unfortunately I can't find anything that does something similar to SQL's like clause for LINQ to Dataset... 不幸的是,我找不到任何类似于LINQ to Dataset的SQL like子句的东西。
UPDATE: Found a similar posting here: LINQ vs. DataTable.Select - How can I get the same results? 更新:在这里找到一个类似的帖子: LINQ vs. DataTable.Select-如何获得相同的结果?
They suggest using i4o which I am not familiar with, but it may be worth investigating (the asker of that question accepted i4o as the answer). 他们建议使用我不熟悉的i4o ,但可能值得调查(该问题的提问者接受了i4o作为答案)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.