public int BatchUpdate(List <TDomain> domains, string where, params Expression <Func <TDomain, object> >[] cols) { if (domains.Count == 0) { return(0); } Expression <Func <TDomain, object> >[] setCols = new Expression <Func <TDomain, object> > [20]; if (!string.IsNullOrEmpty(where)) { var whereCount = Regex.Matches(where, @"\?\d+"); var count = int.Parse(whereCount[whereCount.Count - 1].Value.TrimStart('?')) + 1; if (count != cols.Count()) { throw new ArgumentException("cols 参数长度sql中需要绑定的值不一定"); } if (cols.Count() < whereCount.Count) { throw new ArgumentException("where 字句中的 :数字 参数个数不正确"); } var t = int.Parse(whereCount[0].Value.TrimStart('?')); setCols = cols.Take(t).ToArray(); } else { setCols = cols; } BatchMySqlHelper mySqlHelper = new BatchMySqlHelper(QuerySession); var columnRowData = GetData(domains, cols); string[] usedProperties = setCols.Select(expression => expression.PropertyName()).ToArray(); Table table = GetTable(this.DefaultColumnMapperStrategy); UpdateBuilder <TDomain> updateBuilder = new UpdateBuilder <TDomain>(table, QuerySession.DatabaseInfo.SqlDialect, domains[0], usedProperties); var sql = updateBuilder.CreateSql() + where; if (string.IsNullOrEmpty(where)) { sql = sql.Substring(0, sql.Length - 7); } return(mySqlHelper.BatchInsertOrUpdate(sql, columnRowData)); }
public int BatchDelete(List <TDomain> domains, string where, params Expression <Func <TDomain, object> >[] cols) { if (domains.Count == 0) { return(0);; } BatchMySqlHelper mySqlHelper = new BatchMySqlHelper(QuerySession); string[] usedProperties = cols.Select(expression => expression.PropertyName()).ToArray(); Table table = GetTable(this.DefaultColumnMapperStrategy); DeleteBuilder <TDomain> deleteBuilder = new DeleteBuilder <TDomain>(table, QuerySession.DatabaseInfo.SqlDialect); var sql = deleteBuilder.GetSql() + "where " + where; var columnRowData = GetData(domains, cols); return(mySqlHelper.BatchInsertOrUpdate(sql, columnRowData)); }