读书人

如何把select [field1] from tab wher

发布时间: 2012-12-15 15:16:03 作者: rapoo

怎么把select [field1] from tab where [field1] like '%string1%'转换成linq
怎么把select [field1] from tab where [field1] like '%string1%'转换成linq
[最优解释]
from row in tab
where row.field1.Contains("string1")
select row.field1
[其他解释]
string.Contains("string")相当于'%string%'
string.StartWith("string")相当于'string%'
string.EndWith("string")相当于'%string'
[其他解释]

引用:
怎么把select [field1] from tab where [field1] like '%string1%'转换成linq

var result=db.tab.Where(t=>t.field1.Contains("string1")).Select(t=>t.field1);
[其他解释]
写法很多,首先要了解大概的语句
[其他解释]

from row in tab
where SqlMethods.Like(row.field1 , '%string1%')
select row.field1

[其他解释]
该回复于2011-11-24 13:44:47被版主删除
[其他解释]
谢谢各位,没想到这麽多解答,都很好,我都不知道怎样给分了。我在vs2010帮助中学到实例要比诸位解答复杂的多
[其他解释]
null

读书人网 >.NET

热点推荐