PetaPoco中使用Where in
作者:互联网
petapoco中使用in关键字需要使用命名参数,否则是无效的(或者只查出第一个条件的记录)
例如:
public List<model> GetRate(string from) { using (var db = MDb()) { var sql = new StringBuilder(); sql.Append(@"SELECT * FROM TABLE WHERE 1=1 AND effectivetime<=@effectivetime "); var para = new ArrayList { new { effectivetime = DateTime.Now } }; #region 处理查询条件 if (!string.IsNullOrEmpty(from)) { if (from.IndexOf(",", StringComparison.Ordinal) > 0) { var fromTags = from.Split(','); para.Add(new { from = fromTags }); sql.Append(" AND from.Name IN (@from)"); } else { para.Add(new { from }); sql.Append(" AND from.Name =@from"); } } #endregion return db.Fetch<model>(sql.ToString(), para.ToArray()); } }
标签:para,使用,Add,sql,var,new,Where,PetaPoco,Append 来源: https://www.cnblogs.com/nayilvyangguang/p/13265023.html