条件查询注意
作者:互联网
public List<F_SEAFREIGHT> SeaFreightList(freight model)
{
using (IDbConnection conn = GetConnection(DBType.Forwarder))
{
string query = “select * from F_SEAFREIGHT where TIMESTART <=sysdate and TIMEEND >= sysdate”;
if (!string.IsNullOrEmpty(model.startPort))
{
query = query + " and LOADINGPORTCODE =:startPort";
}
if (!string.IsNullOrEmpty(model.endPort))
{
query = query + " and DESTINATIONPORT =:endPort";
}
if (!string.IsNullOrEmpty(model.shipDateStart))
{
query = query + " and TRANSITDATE >=to_date('" + model.shipDateStart + "', 'yyyy-mm-dd')";
}
if (!string.IsNullOrEmpty(model.shipDateEnd))
{
query = query + " and TRANSITDATE <=to_date('" + model.shipDateEnd + "', 'yyyy-mm-dd')";
}
if (!(string.IsNullOrEmpty(model.shipNo) || model.shipNo == "不限"))
{
query = query + " and CARRIERCODE =:shipNo";
}
var freightList = conn.Query<F_SEAFREIGHT>(query, model).ToList();
return freightList;
}
}
标签:startPort,string,查询,注意,条件,query,model,IsNullOrEmpty,endPort 来源: https://blog.csdn.net/FengxcLf/article/details/95042999