Linq的模糊查询

方式一:
数据源.Where(s =>
s.Name.IndexOf("张")>=0 --------意义等同于 like '%张%' 
s.Name.StartsWith("张") -------- 等同于like '张%' 
s.Name.EndWith("张") -------- 等同于like '%张'
);
方式二:
 var query =
                from product in products
                where product.ProductName.IndexOf(this.txtProduct.Text.Trim()) >= 0 || product.Category.CategoryName.IndexOf(this.txtCatalog.Text.Trim()) >=0
                orderby product.ProductName
                select new { product.ProductName, product.ReorderLevel, product.Category, product.SupplierID };

posted on 2010-06-09 14:46  小呆也行  阅读(5480)  评论(2编辑  收藏  举报

导航