public string GetActualAdditionalColumns()
    {
        List <string> Columns = new List <string>();
        string        Culture = SqlHelper.EscapeQuotes(DataHelper.GetNotEmpty(URLHelper.GetQueryValue(Request.RawUrl, "culture"), "en-US"));

        foreach (string AdditionalColumn in AdditionalColumns.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
        {
            string CleanAdditionalColumn = AdditionalColumn.ToLower().Trim();
            if (DocumentColumnsToDataClass.ContainsKey(CleanAdditionalColumn))
            {
                Columns.Add(string.Format("(select top 1 {0} from CMS_Document where DocumentNodeID = NodeID order by (case when DocumentCulture = '{1}' then 0 else 1 end)) as {0}", CleanAdditionalColumn, Culture));
            }
            else if (ColumnsToDataClass.ContainsKey(CleanAdditionalColumn))
            {
                DataClassInfo  ClassObj    = ColumnsToDataClass[CleanAdditionalColumn];
                DataDefinition ClassFields = new DataDefinition(ClassObj.ClassXmlSchema);
                Columns.Add(string.Format("(select top 1 {0} from {1} where {2} = (select top 1 DocumentForeignKeyValue from CMS_Document where DocumentNodeID = NodeID  order by (case when DocumentCulture = '{3}' then 0 else 1 end))) as {0}"
                                          , CleanAdditionalColumn, ClassObj.ClassTableName, ClassToPrimaryKeyColumn[ClassObj.ClassName.ToLower()], Culture));
            }
            else
            {
                Columns.Add(AdditionalColumn);
            }
        }
        return(string.Join(",", Columns));
    }
Ejemplo n.º 2
0
        /// <summary>
        /// The logging sink and audit sink constructors call this. Defaults are resolved (like ensuring the
        /// primary key is non-null) and obsolete features are migrated to their replacement features so
        /// dependencies in the sink itself can be safely removed as early as possible.
        /// </summary>
        internal void FinalizeConfigurationForSinkConstructor()
        {
            if (_configurationFinalized)
            {
                return;
            }

#pragma warning disable 618 // deprecated: ColumnOptions.AddtionalDataColumns
            if (AdditionalDataColumns != null)
            {
                SelfLog.WriteLine("Deprecated: The \"AdditionalDataColumns\" collection will be removed in a future release. Please use the \"AdditionalColumns\" collection.");

                if (AdditionalColumns == null)
                {
                    AdditionalColumns = new Collection <SqlColumn>();
                }

                foreach (var dataColumn in AdditionalDataColumns)
                {
                    AdditionalColumns.Add(new SqlColumn(dataColumn));
                }
                AdditionalDataColumns = null;
            }
#pragma warning restore 618

            // the constructor sets Id as the PK, remove it if the Id column was removed
            if (!Store.Contains(StandardColumn.Id) && PrimaryKey == Id)
            {
                PrimaryKey = null;
            }

            if (ClusteredColumnstoreIndex)
            {
                if (PrimaryKey != null)
                {
                    PrimaryKey = null;
                    SelfLog.WriteLine("Warning: Removing primary key, incompatible with clustered columnstore indexing.");
                }

                foreach (var stdcol in Store)
                {
                    ColumnstoreCompatibilityCheck(GetStandardColumnOptions(stdcol));
                }
            }

            if (AdditionalColumns != null)
            {
                foreach (var col in AdditionalColumns)
                {
                    if (string.IsNullOrWhiteSpace(col.ColumnName))
                    {
                        throw new ArgumentException("All custom columns must have a valid ColumnName property.");
                    }

                    if (col.DataType == SqlDataTypes.NotSupported)
                    {
                        throw new ArgumentException($"Column \"{col.ColumnName}\" specified an invalid or unsupported SQL column type.");
                    }

                    if (ClusteredColumnstoreIndex)
                    {
                        ColumnstoreCompatibilityCheck(col);
                    }
                }
            }

            // PK must always be NON-NULL
            if (PrimaryKey != null && PrimaryKey.AllowNull == true)
            {
                SelfLog.WriteLine($"Warning: Primary key must be NON-NULL, changing AllowNull property for {PrimaryKey.ColumnName} column.");
                PrimaryKey.AllowNull = false;
            }

            _configurationFinalized = true;
        }