Esempio n. 1
0
        public DocumentTable(DocumentMapping mapping) : base(mapping.TableName)
        {
            // validate to ensure document has an Identity field or property
            mapping.CompileAndValidate();

            _mapping = mapping;

            foreach (var index in mapping.IgnoredIndexes)
            {
                IgnoredIndexes.Add(index);
            }

            var idColumn = new IdColumn(mapping);

            AddColumn(idColumn).AsPrimaryKey();

            if (mapping.TenancyStyle == TenancyStyle.Conjoined)
            {
                AddColumn(mapping.Metadata.TenantId).AsPrimaryKey();

                Indexes.Add(new DocumentIndex(mapping, TenantIdColumn.Name));
            }

            AddColumn <DataColumn>();

            AddIfActive(_mapping.Metadata.LastModified);
            AddIfActive(_mapping.Metadata.Version);
            AddIfActive(_mapping.Metadata.DotNetType);

            AddIfActive(_mapping.Metadata.CorrelationId);
            AddIfActive(_mapping.Metadata.CausationId);
            AddIfActive(_mapping.Metadata.LastModifiedBy);
            AddIfActive(_mapping.Metadata.Headers);

            foreach (var field in mapping.DuplicatedFields.Where(x => !x.OnlyForSearching))
            {
                AddColumn(new DuplicatedFieldColumn(field));
            }

            if (mapping.IsHierarchy())
            {
                Indexes.Add(new DocumentIndex(_mapping, SchemaConstants.DocumentTypeColumn));
                AddColumn(_mapping.Metadata.DocumentType);
            }

            if (mapping.DeleteStyle == DeleteStyle.SoftDelete)
            {
                AddColumn(_mapping.Metadata.IsSoftDeleted);
                Indexes.Add(new DocumentIndex(mapping, SchemaConstants.DeletedColumn));

                AddColumn(_mapping.Metadata.SoftDeletedAt);
            }

            Indexes.AddRange(mapping.Indexes);
            ForeignKeys.AddRange(mapping.ForeignKeys);
        }