public int Delete(IEnumerable <string> ids) { int effected = 0; if (ids != null && ids.Any()) { var sqlBuilder = new StringBuilder(); sqlBuilder.AppendFormat("DELETE FROM {0} WHERE Id IN ", typeof(T).Name); sqlBuilder.Append(" ( "); var list = ids.ToList(); var parameters = new System.Data.SqlClient.SqlParameter[list.Count]; for (int i = 0; i < list.Count; i++) { var paraName = string.Format("@Param{0},", i); sqlBuilder.Append(paraName); parameters[i] = new System.Data.SqlClient.SqlParameter(paraName.Trim(','), list[i]); } sqlBuilder.Remove(sqlBuilder.Length - 1, 1); sqlBuilder.Append(" ) "); var s = sqlBuilder.ToString(); effected = context.ExecuteNonQuery(sqlBuilder.ToString(), parameters); } return(effected); }
/// <summary> /// 提交方法 /// </summary> /// <returns></returns> public void Commit() { if (IsCommited) { return; } using (TransactionScope scope = new TransactionScope()) { foreach (var command in commands) { context.ExecuteNonQuery(command.command, command.parameters); } scope.Complete(); IsCommited = true; } }