正常in查询
string query = @"update house set UpdateTime=getdate() where id in @ids ";
return con.Execute(query, new
{
ids = ids
}) > 0;
当where条件有多个 或者有判断时
直接 **paras.Add(“ids”, ids);(ids为 ‘2,3,4’ )**会报错
直接 and id in (@ids);
paras.Add(“ids”, ids); 会报 ’ 转化数据类型失败’ 的错误
正确做法是:
string query = @"SELECT
ID, Name, State, Province, City, Area FROM house where State=0";
DynamicParameters paras = new DynamicParameters();
if (!string.IsNullOrEmpty(ids))
{
query += @" and id in @ids ";
paras.Add("ids", ids.Split(','));
}
if (!string.IsNullOrEmpty(name))
{
query += @" and Name like @Name";
paras.Add("Name", string.Format("%{0}%", name));
}
return con.Query<HouseModel>(query, paras).ToList();