sql - Linq Multiple Expression -
i use asp.net , ef5. need multiple condition linq. need sql statement.
select * products (prodname '%value1%' , prodname '%value2%' , prodname '%value3%') or (keywords '%value4%')
how can convert linq above sql. i've write it's not enough.
var prodquery = p in _db.products select new searchresult { product = p, searchresulttype = searchresulttype.prod }; //this foreach has in brackets in sql foreach (var s in searchtext.split(' ')) { var temp = s; prodquery = prodquery.where(x => x.product.prodname.contains(temp)); } //and foreach has in bracket in sql , has connect or clause prodquery = prodquery.where(x => x.product.keywords.contains(searchtext));
try this:
var keywords = searchtext.split(' '); var results = _db.products.where(p => keywords.any(kw => kw.contains(p.prodname)) || p.keywords.contains(searchtext)) .select(x => new searchresult() { product = x, searchresulttype = searchresulttype.prod });
Comments
Post a Comment