/// <summary> /// Adds "<paramref name="columnName" /> in (<paramref name="parameters" />.ParameterName, ...)" /// expression to the clause. /// If <paramref name="parameters"/> is null or contains no elements then nothing will be added. /// </summary> public static SqlClause AddIn(this SqlClause sqlClause, [NotNull] string columnName, [CanBeNull] IEnumerable <IDbDataParameter> parameters) { if (parameters == null) { return(sqlClause); } var list = parameters as IReadOnlyList <IDbDataParameter>; if (list == null) { list = parameters.ToList(); } if (list.Count == 0) { return(sqlClause); } if (list.Count == 1) { return(sqlClause.AddEquals(columnName, list[0])); } var expression = new StringBuilder(columnName); expression.Append(" in ("); for (var k = 0; k < list.Count; k++) { var p = list[k]; if (k > 0) { expression.Append(", "); } expression.Append(p.ParameterName); sqlClause.Add(p); } expression.Append(')'); sqlClause.Add(expression.ToString()); return(sqlClause); }