我有这个搜索代码.
public List<Tbl_Product> ProductSearch(DateTime startdate, DateTime enddate, string productname, int suply)
{
    var q = _db.Tbl_Product
            .Where(model => 
                model.DateReg == startdate && 
                model.DateReg == enddate)
            .Where(model => 
                model.ProductName.Contains(productname))
            .Where({});
}
现在我需要在Last中插入此代码Where.
if(suply == 1)
{
    model.Suply > 0 ;
}
else
{
    model.Suply = 0;
}
我该怎么办?
我个人不会在Where子句中这样做,因为这意味着你将suply变量传递给数据库.
var q = _db.Tbl_Product
    .Where(model => model.DateReg == startdate 
                 && model.DateReg == enddate
                 && model.ProductName.Contains(productname));
if(suply == 1)
{
    q = q.Where(model => model.Suply > 0);
}
else
{
    q = q.Where(model => model.Suply == 0);
}
但是,如果您真的坚持要立即执行所有操作:
.Where(model => (suply == 1 && model.Suply > 0)
             || (suply != 1 && model.Suply == 0));