多字段动态查询

private bool GetCondition(MerchantTravelXSJL tb, string key, string searchCity, string phoneNumber, DateTime? buyStartDate, DateTime? buyEndDate, int? checkStatus)
{
bool boolResult = true;

if (!String.IsNullOrEmpty(key))
{
boolResult &= tb.MERCHANTNAME == key;
}
if (!String.IsNullOrEmpty(searchCity))
{
boolResult &= tb.CITYCODE == searchCity;
}
if (!String.IsNullOrEmpty(phoneNumber))
{
boolResult &= tb.CELLPHONENUMBER == phoneNumber;

}
if (buyStartDate.HasValue)
{
boolResult &= (tb.CREATEDTIME >= buyStartDate.Value);
}
if (buyEndDate.HasValue)
{
boolResult &= tb.CREATEDTIME < buyEndDate.Value;
}
if (checkStatus.HasValue)
{
boolResult &= tb.STATUS == checkStatus;
}
return boolResult;
}

原文地址:https://www.cnblogs.com/fyy1003668657/p/6817149.html