public string GenerateUpdate(
            ICollection <DbUpdateCommandTree> commandTrees,
            string rowsAffectedParameter)
        {
            if (!commandTrees.Any <DbUpdateCommandTree>())
            {
                return((string)null);
            }
            StringBuilder       sql = new StringBuilder();
            List <SqlParameter> parameters;

            sql.AppendLine(DmlSqlGenerator.GenerateUpdateSql(commandTrees.First <DbUpdateCommandTree>(), this._sqlGenerator, out parameters, false, true));
            foreach (DbUpdateCommandTree tree in commandTrees.Skip <DbUpdateCommandTree>(1))
            {
                sql.Append(DmlSqlGenerator.GenerateUpdateSql(tree, this._sqlGenerator, out parameters, false, true));
                sql.AppendLine("AND @@ROWCOUNT > 0");
                sql.AppendLine();
            }
            List <DbUpdateCommandTree> list = commandTrees.Where <DbUpdateCommandTree>((Func <DbUpdateCommandTree, bool>)(ct => ct.Returning != null)).ToList <DbUpdateCommandTree>();

            if (list.Any <DbUpdateCommandTree>())
            {
                DmlFunctionSqlGenerator.ReturningSelectSqlGenerator selectSqlGenerator = new DmlFunctionSqlGenerator.ReturningSelectSqlGenerator();
                foreach (DbUpdateCommandTree updateCommandTree in list)
                {
                    updateCommandTree.Target.Expression.Accept((DbExpressionVisitor)selectSqlGenerator);
                    updateCommandTree.Returning.Accept((DbExpressionVisitor)selectSqlGenerator);
                    updateCommandTree.Predicate.Accept((DbExpressionVisitor)selectSqlGenerator);
                }
                sql.AppendLine(selectSqlGenerator.Sql);
                sql.AppendLine();
            }
            DmlFunctionSqlGenerator.AppendSetRowsAffected(sql, rowsAffectedParameter);
            return(sql.ToString().TrimEnd());
        }
        public string GenerateUpdate(ICollection <DbUpdateCommandTree> commandTrees, string rowsAffectedParameter)
        {
            DebugCheck.NotNull(commandTrees);

            if (!commandTrees.Any())
            {
                return(null);
            }

            List <SqlParameter> _;

            var sql = new StringBuilder();

            sql.AppendLine(
                DmlSqlGenerator.GenerateUpdateSql(
                    commandTrees.First(),
                    _sqlGenerator,
                    out _,
                    generateReturningSql: false));

            foreach (var commandTree in commandTrees.Skip(1))
            {
                sql.Append(
                    DmlSqlGenerator.GenerateUpdateSql(
                        commandTree,
                        _sqlGenerator,
                        out _,
                        generateReturningSql: false));

                sql.AppendLine("AND @@ROWCOUNT > 0");
                sql.AppendLine();
            }

            var returningCommandTrees
                = commandTrees
                  .Where(ct => ct.Returning != null)
                  .ToList();

            if (returningCommandTrees.Any())
            {
                var returningSelectSqlGenerator = new ReturningSelectSqlGenerator();

                foreach (var commandTree in returningCommandTrees)
                {
                    commandTree.Target.Expression.Accept(returningSelectSqlGenerator);
                    commandTree.Returning.Accept(returningSelectSqlGenerator);
                    commandTree.Predicate.Accept(returningSelectSqlGenerator);
                }

                sql.AppendLine(returningSelectSqlGenerator.Sql);
                sql.AppendLine();
            }

            AppendSetRowsAffected(sql, rowsAffectedParameter);

            return(sql.ToString().TrimEnd());
        }