rwhn.net
当前位置:首页 >> linq whErE likE >>

linq whErE likE

数据源.Where(s => s.Name.IndexOf("张")>=0 --------意义等同於 like '%张%' s.Name.StartsWith("张") -------- 等同於like '张%' s.Name.EndWith("张") -------- 等同於like '%张');

//using System.Data.Objects.SqlClient; private void btnLike_Click(object sender, EventArgs e) { NorthwindEntities en = new NorthwindEntities(); var v = en.Employees.Where(x => SqlFunctions.PatIndex("%a%e%", x.FirstName) > 0); ...

query = from c in tbs where c.sx != "类别" && c.path_tbname.Contains(tName.Text) orderby c.id select c; Contains 等于 like '%'+tName.Text+'%'

首先明确一条,楼上的同学的作法是可以的。 然后说正事。 楼主的sql写的不好,不建议这样写,因为使用CONVERT将日期列转换为字符串后再匹配的话,会导致数据库索引失效(如果有的话),进而导致全表扫描。并且由于“2011-”这样的字符串依赖于操作...

query = from c in tbs where c.sx != "类别" && c.path_tbname.Contains(tName.Text) orderby c.id select c; Contains 就等于 like '%'+tName.Text+'%'

你可以使用一些不会报错的方式将object转换为字符串 如 str_max=string.Format("{0}",myReader[0]); 当yReader[0]为null时将返回string.Empty,此方法永远不返回NULL str_max=myReader[0] as string; 当转换失败时不会出异常而是返回null

db.NAMES.Where (p =>SqlMethods.Like(p.NAMES_TID,"%[0-9]%")) --------------------

l.Where(ele=>ele.Length == 5 && ele.StartsWith("ss"))

query = from c in tbs where c.sx != "类别" && c.path_tbname.Contains(tName.Text) orderby c.id select c; Contains 就等于 like '%'+tName.Text+'%'

query = from c in tbs where c.sx != "类别" && c.path_tbname.Contains(tName.Text) orderby c.id select c; Contains 就等于 like '%'+tName.Text+'%'

网站首页 | 网站地图
All rights reserved Powered by www.rwhn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com