Пример #1
0
        /// <summary>
        ///     Constructs an update statement for a single entity.
        /// </summary>
        protected override string ConstructFullSingleUpdateStatementInternal()
        {
            if (RefreshOnUpdateProperties.Length == 0)
            {
                return(base.ConstructFullSingleUpdateStatementInternal());
            }

            var dbUpdatedOutputColumns = string.Join(",",
                                                     RefreshOnUpdateProperties.Select(propInfo => $"inserted.{GetColumnName(propInfo, null, true)}"));
            var dbGeneratedColumns = string.Join(",",
                                                 RefreshOnUpdateProperties.Select(propInfo => $"{GetColumnName(propInfo, null, true)}"));

            // the union will make the constraints be ignored
            return(ResolveWithCultureInvariantFormatter($@"
                SELECT *
                    INTO #temp
                    FROM (SELECT {dbGeneratedColumns} FROM {GetTableName()} WHERE 1=0
                        UNION SELECT {dbGeneratedColumns} FROM {GetTableName()} WHERE 1=0) as u;

                UPDATE {GetTableName()}
                    SET {ConstructUpdateClause()}
                    OUTPUT {dbUpdatedOutputColumns} INTO #temp
                    WHERE {ConstructKeysWhereClause()}

                SELECT * FROM #temp"));
        }
Пример #2
0
 /// <summary>
 ///     Constructs a column selection of all columns to be refreshed on update of the form
 ///     <code>@PropertyName1,@PropertyName2...</code>
 /// </summary>
 /// <returns></returns>
 protected virtual string ConstructRefreshOnUpdateColumnSelection()
 {
     return(string.Join(",", RefreshOnUpdateProperties.Select(propInfo => GetColumnName(propInfo, null, true))));
 }