这里怎么设置linq 查询 where条件,在哪里设置查询条件。我要查询Title

2025-04-25 10:01:30
推荐回答(1个)
回答1:

如下查询title 是空的检索:
ExtShopDataContext dc = new ExtShopDataContext();
var q = dc.T_Products.OrderByDescending(m => m.CreateTime)
.Where(p=>p.Title=="")
.Select( m => new
{
m.ProductID,
m.Title,
m.TotalRating,
m.UnitPrice,
m.SmallImageUrl,
m.MarketPrice
}

).Take(15);

---
如果这样
Where(p=>new string[]{ "E", "H", "F" }.Contains(p.Title)) 就变成 title 是 E,H,.F 的集合,或关系
以上转化为in操作
Where(p=>p.Title.Contains(""))
这个就转化为like 操作
你可以换成别的字符,我的是空字符。