开发者

linq to dataset equivalent of SQL LIKE clause

What is the linq equivalent of a SQL clause like WHERE UserName LIKE 'fr_d'?

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.开发者_Go百科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!)


Like this:

table.Where(row => row.StringColumn.StartsWith("prefix"))

(You may also want to call Contains or 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.
If you do, make sure to create the RegEx object outside the Where call so that it doesn't get parsed for each row.


I belive this is what you really want. It will allow Fr{any one character}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...

UPDATE: Found a similar posting here: LINQ vs. DataTable.Select - How can I get the same results?

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜