日期:2014-05-20  浏览次数:20689 次

怎么把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