internal static void PrepareSqlServerUpdateStatement <T>(IDbCommand dbCmd, SqlExpression <T> q, T item, bool excludeDefaults = false)
        {
            q.CopyParamsTo(dbCmd);

            var modelDef        = q.ModelDef;
            var dialectProvider = q.DialectProvider;

            var setFields = StringBuilderCache.Allocate();

            foreach (var fieldDef in modelDef.FieldDefinitions)
            {
                if (fieldDef.ShouldSkipUpdate())
                {
                    continue;
                }
                if (fieldDef.IsRowVersion)
                {
                    continue;
                }
                if (q.UpdateFields.Count > 0 &&
                    !q.UpdateFields.Contains(fieldDef.Name) ||
                    fieldDef.AutoIncrement)
                {
                    continue; // added
                }
                var value = fieldDef.GetValue(item);
                if (excludeDefaults &&
                    (value == null || (!fieldDef.IsNullable && value.Equals(value.GetType().GetDefaultValue()))))
                {
                    continue;
                }

                if (setFields.Length > 0)
                {
                    setFields.Append(", ");
                }

                var param = dialectProvider.AddParam(dbCmd, value, fieldDef.ColumnType);
                setFields
                .Append(dialectProvider.GetQuotedColumnName(fieldDef.FieldName))
                .Append("=")
                .Append(param.ParameterName);
            }

            var strFields = StringBuilderCache.ReturnAndFree(setFields);

            if (strFields.Length == 0)
            {
                throw new ArgumentException("No non-null or non-default values were provided for type: " + typeof(T).Name);
            }

            dbCmd.CommandText = string.Format("UPDATE {0} SET {1} {2}",
                                              dialectProvider.GetQuotedTableName(modelDef), strFields, q.WhereExpression);
        }