C# 将数组拼接为字符串 string.Join 的使用
- param.ids为String[] 数组
StringBuilder sql = new StringBuilder();
sql.Append($" select * from school_relation where id in ('{string.Join("','", param.ids)}') ;");
- 过滤条件为集合也可以这样写
public List<string> GetCertArray(string[] certificate_nums, Guid id) { dynamic date_sql_parames = new System.Dynamic.ExpandoObject(); date_sql_parames.Id = id; date_sql_parames.certificateNums = certificate_nums.ToList(); var date_sql_str = $"select Certificate_Num from TabA where id=@Id and certificate_num in @certificateNums ;"; var list = _partnersDal.Query<string>(date_sql_str, date_sql_parames); return list; }