Пример #1
0
        public void FindMissingColumn()
        {
            var table = new DocumentTable("Entities");

            table.Register(new Column("Number", typeof(int)));
            schema.Add(table);

            configuration.Document <Entity>();

            var commands = migrator.CalculateSchemaChanges(schema, configuration).Cast <RemoveColumn>().ToList();

            commands[0].Table.ShouldBe(GetTableFor <Entity>());
            commands[0].Name.ShouldBe("Number");
        }
Пример #2
0
        public List <ApplicationUser> GetSignUsers(DocumentTable docuTable)
        {
            List <ApplicationUser> signUsers = new List <ApplicationUser>();

            if (docuTable != null)
            {
                IEnumerable <WFTrackerTable> trackerTables = _WorkflowTrackerService.GetCurrentStep(x => x.DocumentTableId == docuTable.Id && x.SignUserId == null);

                foreach (var trackerTable in trackerTables)
                {
                    if (trackerTable.Users != null)
                    {
                        foreach (var trackUser in trackerTable.Users)
                        {
                            signUsers.Add(_AccountService.Find(trackUser.UserId));
                        }
                    }
                }

                List <ApplicationUser> delegationUserCheck = signUsers.ToList();

                foreach (var user in delegationUserCheck)
                {
                    var delegationItems = _DelegationService.GetPartial(x => x.EmplTableTo.ApplicationUserId == user.Id &&
                                                                        x.DateFrom <= DateTime.UtcNow && x.DateTo >= DateTime.UtcNow &&
                                                                        x.isArchive == false && x.CompanyTableId == user.CompanyTableId);

                    foreach (var delegationItem in delegationItems)
                    {
                        if (delegationItem.GroupProcessTableId != null || delegationItem.ProcessTableId != null)
                        {
                            if (delegationItem.ProcessTableId == docuTable.ProcessTableId)
                            {
                                signUsers.Add(_AccountService.Find(delegationItem.EmplTableFrom.ApplicationUserId));
                            }
                            else if (_ProcessService.Find(docuTable.ProcessTableId).GroupProcessTableId == delegationItem.GroupProcessTableId)
                            {
                                signUsers.Add(_AccountService.Find(delegationItem.EmplTableFrom.ApplicationUserId));
                            }
                        }
                        else
                        {
                            signUsers.Add(_AccountService.Find(delegationItem.EmplTableFrom.ApplicationUserId));
                        }
                    }
                }
            }

            return(signUsers);
        }
Пример #3
0
        public void can_spot_an_extra_index()
        {
            theMapping.Index(x => x.UserName);

            writeTable();

            theMapping.Index(x => x.FirstName);
            var table = new DocumentTable(theMapping);

            var delta = table.FetchDelta(_conn);

            delta.IndexChanges.Count.ShouldBe(1);
            delta.IndexRollbacks.Count.ShouldBe(1);
        }
Пример #4
0
        public void write_ddl_in_create_if_not_exists_mode()
        {
            var users = DocumentMapping.For <User>();
            var table = new DocumentTable(users);
            var rules = new DdlRules
            {
                TableCreation = CreationStyle.CreateIfNotExists
            };

            var ddl = table.ToDDL(rules);

            ddl.ShouldNotContain("DROP TABLE IF EXISTS public.mt_doc_user CASCADE;");
            ddl.ShouldContain("CREATE TABLE IF NOT EXISTS public.mt_doc_user");
        }
Пример #5
0
        public DocumentSchema(DocumentMapping mapping)
        {
            _mapping = mapping;

            Table  = new DocumentTable(_mapping);
            Upsert = new UpsertFunction(_mapping);
            Insert = new InsertFunction(_mapping);
            Update = new UpdateFunction(_mapping);

            if (_mapping.UseOptimisticConcurrency)
            {
                Overwrite = new OverwriteFunction(_mapping);
            }
        }
Пример #6
0
        public void write_ddl_in_default_drop_then_create_mode()
        {
            var users = DocumentMapping.For <User>();
            var table = new DocumentTable(users);
            var rules = new DdlRules
            {
                TableCreation = CreationStyle.DropThenCreate
            };

            var ddl = table.ToDDL(rules);

            ddl.ShouldContain("DROP TABLE IF EXISTS public.mt_doc_user CASCADE;");
            ddl.ShouldContain("CREATE TABLE public.mt_doc_user");
        }
Пример #7
0
        public void not_matching_with_columns_of_same_name_that_are_different()
        {
            var users    = DocumentMapping.For <User>();
            var actual   = new DocumentTable(users);
            var expected = new DocumentTable(users);

            actual.ReplaceOrAddColumn("id", "int");

            var diff = new TableDelta(expected, actual);

            diff.Matches.ShouldBeFalse();

            diff.Different.Single().Name.ShouldBe("id");
        }
Пример #8
0
        public void do_not_drop_unchanged_index()
        {
            StoreOptions(_ =>
            {
                _.AutoCreateSchemaObjects         = AutoCreate.CreateOrUpdate;
                _.Advanced.DdlRules.TableCreation = CreationStyle.CreateIfNotExists;
                _.Schema.For <Bug1043.Thing>().Index(x => x.Name, x =>
                {
                    x.IndexName    = "Test_Index";
                    x.IsUnique     = true;
                    x.Casing       = ComputedIndex.Casings.Lower;
                    x.IsConcurrent = true;
                });
            });

            using (var session = theStore.OpenSession())
            {
                session.Insert(new Bug1043.Thing
                {
                    Id    = "test/1",
                    Name  = "A Thing",
                    Count = 1
                });

                session.SaveChanges();
            }

            var mapping = DocumentMapping.For <Bug1043.Thing>();

            mapping.DatabaseSchemaName = SchemaName;
            mapping.Index(x => x.Name, x =>
            {
                x.IndexName    = "Test_Index";
                x.IsUnique     = true;
                x.Casing       = ComputedIndex.Casings.Lower;
                x.IsConcurrent = true;
            });
            var docTable = new DocumentTable(mapping);

            using (var connection = new Npgsql.NpgsqlConnection(ConnectionSource.ConnectionString))
            {
                connection.Open();

                var diff = docTable.FetchDelta(connection);

                Assert.NotNull(diff);
                Assert.Equal(0, diff.IndexChanges.Count);
                Assert.Equal(0, diff.IndexRollbacks.Count);
            }
        }
        //[Fact] -- unreliable in CI
        public void can_add_same_primary_key_to_multiple_tenant()
        {
            var guid  = Guid.NewGuid();
            var store = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Policies.AllDocumentsAreMultiTenanted();
                _.Logger(new ConsoleMartenLogger());
            });

            store.Tenancy.Default.EnsureStorageExists(typeof(Target));
            var existing = store.Tenancy.Default.DbObjects.ExistingTableFor(typeof(Target));
            var mapping  = store.Options.Storage.MappingFor(typeof(Target));
            var expected = new DocumentTable(mapping);

            var delta = new TableDelta(expected, existing);

            delta.Matches.ShouldBeTrue();

            using (var session = store.OpenSession("123"))
            {
                var target = Target.Random();
                target.Id     = guid;
                target.String = "123";
                session.Store("123", target);
                session.SaveChanges();
            }
            using (var session = store.OpenSession("abc"))
            {
                var target = Target.Random();
                target.Id     = guid;
                target.String = "abc";
                session.Store("abc", target);
                session.SaveChanges();
            }

            using (var session = store.OpenSession("123"))
            {
                var target = session.Load <Target>(guid);
                target.ShouldNotBeNull();
                target.String.ShouldBe("123");
            }

            using (var session = store.OpenSession("abc"))
            {
                var target = session.Load <Target>(guid);
                target.ShouldNotBeNull();
                target.String.ShouldBe("abc");
            }
        }
Пример #10
0
        public void not_matching_with_extra_columns()
        {
            var users    = DocumentMapping.For <User>();
            var actual   = new DocumentTable(users);
            var expected = new DocumentTable(users);

            var tableColumn = new TableColumn("new", "varchar");

            actual.AddColumn(tableColumn);

            var diff = new TableDelta(expected, actual);

            diff.Matches.ShouldBeFalse();
            diff.Extras.Single().ShouldBe(tableColumn);
        }
Пример #11
0
        public void add_the_tenant_id_column_when_it_is_conjoined_tenancy()
        {
            var options = new StoreOptions();

            options.Connection(ConnectionSource.ConnectionString);
            options.Policies.AllDocumentsAreMultiTenanted();

            var mapping = new DocumentMapping(typeof(User), options);

            mapping.TenancyStyle = TenancyStyle.Conjoined;

            var table = new DocumentTable(mapping);

            table.Any(x => x is TenantIdColumn).ShouldBeTrue();
        }
Пример #12
0
        public void CanExecuteOnMultipleThreads()
        {
            UseGlobalTempTables();

            UseTableNamePrefix(Guid.NewGuid().ToString());
            Document <Entity>().With(x => x.Property);

            InitializeStore();

            Parallel.For(0, 10, x =>
            {
                var table = new DocumentTable("Entities");
                store.Insert(table, NewId(), new { Property = "Asger", Version = 1 });
            });
        }
Пример #13
0
        public static IEnumerable <QueryResult <T> > Query <T>(
            this IDocumentStore store, DocumentTable table, string @join, out QueryStats stats, bool top1 = false, string select = null, string where = "",
            Window window = null, string orderby = "", bool includeDeleted = false, object parameters = null)
        {
            using (var tx = store.BeginTransaction())
            {
                var(queryStats, rows) = tx.Query <T>(table, @join, top1, @select, @where, window, @orderby, includeDeleted, parameters);

                tx.Complete();

                stats = queryStats;

                return(rows);
            }
        }
Пример #14
0
        public void FindMissingColumn()
        {
            var table = new DocumentTable("Entities");

            table.Add(new Column <int>("Number"));

            schema.Add(table.Name, table.Columns.Select(x => x.Name).ToList());

            configuration.Document <Entity>();

            var commands = migrator.CalculateSchemaChanges(schema, configuration).Cast <RemoveColumn>().ToList();

            commands[0].Table.ShouldBe(GetTableFor <Entity>());
            commands[0].Name.ShouldBe("Number");
        }
Пример #15
0
        public List <WFTrackerUsersTable> GetUsersSLAStatus(DocumentTable docuTable, SLAStatusList status)
        {
            IEnumerable <WFTrackerTable> items = GetCurrentSignStep(docuTable.Id);
            List <WFTrackerUsersTable>   users = new List <WFTrackerUsersTable>();

            foreach (var item in items)
            {
                if (item.SLAStatus() == status)
                {
                    users.AddRange(item.Users);
                }
            }

            return(users);
        }
Пример #16
0
        /// <summary>
        /// Creates result table based on surface results.
        /// </summary>
        /// <param name="resInPtCollection">Result in point collection</param>
        /// <param name="resultTypes">The type of results, values and description to use in the table.</param>
        /// <param name="document">Revit document</param>
        /// <param name="elementType">Type of element</param>
        /// <returns>Document table containing surface results</returns>
        private DocumentTable CreateResultTableForSurfaceElements(List <ResultInPointSurface> resInPtCollection, IEnumerable <ResultTypeSurface> resultTypes, Autodesk.Revit.DB.Document document, ElementType elementType)
        {
            // results table data
            int rowsCount = 1 + resInPtCollection.Count(),
                colsCount = (ElementType.Wall == elementType ? 3 : 2) + resultTypes.Count();

            Units         units       = document.GetUnits();
            DocumentTable resultTable = new DocumentTable(rowsCount, colsCount);

            resultTable.HeaderColumnsCount = ElementType.Wall == elementType ? 3 : 2;
            resultTable.HeaderRowsCount    = 1;

            // results table data
            List <ResultTypeSurface> typesToPresent = ElementType.Wall == elementType ? new List <ResultTypeSurface>()
            {
                ResultTypeSurface.X, ResultTypeSurface.Y, ResultTypeSurface.Z
            } : new List <ResultTypeSurface>()
            {
                ResultTypeSurface.X, ResultTypeSurface.Y
            };

            typesToPresent.AddRange(resultTypes);

            int colId = 0;

            foreach (ResultTypeSurface resultType in typesToPresent)
            {
                resultTable[0, colId].Elements.Add(new DocumentText(ResultDescription(elementType, resultType)));
                UnitType        unitType        = resultType.GetUnitType();
                DisplayUnitType displayUnitType = Utility.UnitsConverter.GetInternalUnit(unitType);

                int rowId = 1;
                foreach (ResultInPointSurface resultInPoint in resInPtCollection)
                {
                    if (DisplayUnitType.DUT_UNDEFINED != displayUnitType)
                    {
                        resultTable[rowId++, colId].Elements.Add(new DocumentValue(resultInPoint[resultType], displayUnitType, unitType, units));
                    }
                    else
                    {
                        resultTable[rowId++, colId].Elements.Add(new DocumentText(resultInPoint[resultType].ToString()));
                    }
                }
                colId++;
            }

            return(resultTable);
        }
Пример #17
0
        public async Task can_add_same_primary_key_to_multiple_tenant()
        {
            var guid = Guid.NewGuid();

            await theStore.EnsureStorageExistsAsync(typeof(Target));

            var existing = await theStore.Tenancy.Default.Database.ExistingTableFor(typeof(Target));

            var mapping  = theStore.Options.Storage.MappingFor(typeof(Target));
            var expected = new DocumentTable(mapping);

            var delta = new TableDelta(expected, existing);

            delta.Difference.ShouldBe(SchemaPatchDifference.None);

            using (var session = theStore.OpenSession("123"))
            {
                var target = Target.Random();
                target.Id     = guid;
                target.String = "123";
                session.ForTenant("123").Store(target);
                await session.SaveChangesAsync();
            }

            using (var session = theStore.OpenSession("abc"))
            {
                var target = Target.Random();
                target.Id     = guid;
                target.String = "abc";
                session.ForTenant("abc").Store(target);
                await session.SaveChangesAsync();
            }

            using (var session = theStore.OpenSession("123"))
            {
                var target = session.Load <Target>(guid);
                target.ShouldNotBeNull();
                target.String.ShouldBe("123");
            }

            using (var session = theStore.OpenSession("abc"))
            {
                var target = session.Load <Target>(guid);
                target.ShouldNotBeNull();
                target.String.ShouldBe("abc");
            }
        }
        private void searchable(Expression <Func <Target, object> > expression)
        {
            StoreOptions(_ =>
            {
                _.Schema.For <Target>().Duplicate(expression);
            });

            theStore.Tenancy.Default.StorageFor <Target>().ShouldNotBeNull();

            var existing = theStore.TableSchema(typeof(Target));

            var configured = new DocumentTable(theStore.Storage.MappingFor(typeof(Target)).As <DocumentMapping>());

            var delta = new TableDelta(configured, existing);

            delta.Difference.ShouldBe(SchemaPatchDifference.None);
        }
Пример #19
0
        public void FindDocument()
        {
            if (string.IsNullOrWhiteSpace(TableName))
            {
                return;
            }

            var table = new DocumentTable(TableName);

            var sw = Stopwatch.StartNew();

            StatusMessage = string.Format("Getting document {0} from table {1}", documentId, table.Name);
            Loading       = true;
            FindDocument(table, documentId);
            Loading       = false;
            StatusMessage = string.Format("Fetched document {0} in {1}ms", documentId, sw.ElapsedMilliseconds);
        }
Пример #20
0
        public void can_add_same_primary_key_to_multiple_tenant()
        {
            var guid = Guid.NewGuid();

            theStore.Tenancy.Default.EnsureStorageExists(typeof(Target));
            var existing = theStore.Tenancy.Default.DbObjects.ExistingTableFor(typeof(Target));
            var mapping  = theStore.Options.Storage.MappingFor(typeof(Target));
            var expected = new DocumentTable(mapping);

            var delta = new TableDelta(expected, existing);

            delta.Matches.ShouldBeTrue();

            using (var session = theStore.OpenSession("123"))
            {
                var target = Target.Random();
                target.Id     = guid;
                target.String = "123";
                session.Store("123", target);
                session.SaveChanges();
            }

            using (var session = theStore.OpenSession("abc"))
            {
                var target = Target.Random();
                target.Id     = guid;
                target.String = "abc";
                session.Store("abc", target);
                session.SaveChanges();
            }

            using (var session = theStore.OpenSession("123"))
            {
                var target = session.Load <Target>(guid);
                SpecificationExtensions.ShouldNotBeNull(target);
                target.String.ShouldBe("123");
            }

            using (var session = theStore.OpenSession("abc"))
            {
                var target = session.Load <Target>(guid);
                SpecificationExtensions.ShouldNotBeNull(target);
                target.String.ShouldBe("abc");
            }
        }
        public void AcceptsConcurrentWrites()
        {
            UseRealTables();

            Document <Entity>().With(x => x.Number);

            store.Initialize();

            var id    = NewId();
            var table = new DocumentTable("Entities");
            var etag  = store.Insert(table, id, new
            {
                Discriminator = typeof(Entity).AssemblyQualifiedName,
                Version       = 0,
                Document      = configuration.Serializer.Serialize(new Entity())
            });

            var gate1 = new ManualResetEvent(false);
            var gate2 = new ManualResetEvent(false);

            UseMigrations(new InlineMigration(1, new ChangeDocument <Entity>((serializer, bytes) =>
            {
                gate1.Set();
                Thread.Sleep(1000);
                return(bytes);
            })));

            bool?failed = null;

            new DocumentMigrationRunner()
            .Run(store)
            .ContinueWith(x =>
            {
                failed = x.IsFaulted;
                gate2.Set();
            });

            gate1.WaitOne();

            store.Update(table, id, etag, new {});

            gate2.WaitOne();

            failed.ShouldBe(false);
        }
Пример #22
0
        public void can_do_substitutions()
        {
            var mapping = DocumentMapping.For <User>();

            mapping.Duplicate(x => x.FirstName);

            var table = new DocumentTable(mapping);

            table.BuildTemplate($"*{DdlRules.SCHEMA}*").ShouldBe($"*{table.Identifier.Schema}*");
            table.BuildTemplate($"*{DdlRules.TABLENAME}*").ShouldBe($"*{table.Identifier.Name}*");
            table.BuildTemplate($"*{DdlRules.COLUMNS}*")
            .ShouldBe($"*id, data, mt_last_modified, mt_version, mt_dotnet_type, first_name*");
            table.BuildTemplate($"*{DdlRules.NON_ID_COLUMNS}*")
            .ShouldBe($"*data, mt_last_modified, mt_version, mt_dotnet_type, first_name*");

            table.BuildTemplate($"*{DdlRules.METADATA_COLUMNS}*")
            .ShouldBe("*mt_last_modified, mt_version, mt_dotnet_type*");
        }
Пример #23
0
        public DateTime?GetSLAPerformDate(Guid DocumentId, DateTime CreatedDate, double SLAOffset)
        {
            DocumentTable documentTable = Find(DocumentId);

            if (documentTable != null && documentTable.ProcessTable != null)
            {
                WorkScheduleTable scheduleTable = _WorkScheduleService.Find(documentTable.ProcessTable.WorkScheduleTableId);
                if (scheduleTable != null)
                {
                    CreatedDate = GetWorkStartDate(CreatedDate, scheduleTable);
                    double SLAMinutes = (SLAOffset * 60);

                    return(GetSLAAddOffset(scheduleTable, CreatedDate, SLAMinutes));
                }
            }

            return(null);
        }
Пример #24
0
        public void UtilityColsAreRemovedFromQueryResults()
        {
            Document <Entity>();

            var table = new DocumentTable("Entities");

            store.Insert(table, NewId(), new { Version = 1 });

            var result1 = store.Query(table, out _, window: new SkipTake(0, 2)).Single();

            result1.ContainsKey(new Column("RowNumber", typeof(int))).ShouldBe(false);
            result1.ContainsKey(new Column("TotalResults", typeof(int))).ShouldBe(false);

            var result2 = store.Query <object>(table, out _, window: new SkipTake(0, 2)).Single();

            ((IDictionary <string, object>)result2.Data).ContainsKey("RowNumber").ShouldBe(false);
            ((IDictionary <string, object>)result2.Data).ContainsKey("TotalResults").ShouldBe(false);
        }
Пример #25
0
        public static void AddTable(WordprocessingDocument doc, DocumentTable tableModel)
        {
            var body = doc.MainDocumentPart
                       .Document.Body;

            var elem = body.ChildElements.FirstOrDefault(el => el.InnerText == tableModel.PlacingText);

            if (elem == null)
            {
                throw new ApplicationException($"Не найден элемент с внутренним текстом '{tableModel.PlacingText}', " +
                                               $"вместо которого нужно вставить таблицу.");
            }

            var table = DocTableCreator.GetTable(tableModel);

            elem.InsertAfterSelf(table);

            elem.Remove();
        }
        public void does_not_regenerate_the_login_table()
        {
            var existing = theStore.TableSchema(typeof(Login));

            var mapping    = theStore.Tenancy.Default.MappingFor(typeof(Login));
            var configured = new DocumentTable(mapping.As <DocumentMapping>());

            if (!existing.Equals(configured))
            {
                var writer = new StringWriter();
                writer.WriteLine("Expected:");
                configured.Write(theStore.Schema.DdlRules, writer);
                writer.WriteLine();
                writer.WriteLine("But from the database, was:");
                existing.Write(theStore.Schema.DdlRules, writer);

                throw new Exception(writer.ToString());
            }
        }
Пример #27
0
        /// <summary>
        /// Presentation file data source
        /// </summary>
        /// <returns></returns>
        public static GroupDocs.Assembly.Data.DocumentTable PresentationData()
        {
            // Do not extract column names from the first row, so that the first row to be treated as a data row.
            // Limit the largest row index, so that only the first four data rows to be loaded.
            DocumentTableOptions options = new DocumentTableOptions();

            options.MaxRowIndex = 3;

            // Use data of the _second_ table in the document.
            DocumentTable table = new DocumentTable(presentationDataFile, 1, options);

            // Check column count and names.
            Debug.Assert(table.Columns.Count == 2);

            // NOTE: Default column names are used, because we do not extract the names from the first row.
            Debug.Assert(table.Columns[0].Name == "Column1");
            Debug.Assert(table.Columns[1].Name == "Column2");
            return(table);
        }
Пример #28
0
        public Guid SaveDocument(dynamic viewTable, string tableName, Guid processId, Guid fileId, string currentUserName = "")
        {
            string localUserName = getCurrentUserName(currentUserName);

            var docuTable = new DocumentTable();

            docuTable.ProcessTableId = processId;
            docuTable.CreatedDate    = DateTime.UtcNow;
            docuTable.ModifiedDate   = docuTable.CreatedDate;
            docuTable.DocumentState  = DocumentState.Created;
            docuTable.FileId         = fileId;

            ApplicationUser user = _AccountService.FirstOrDefault(x => x.UserName == localUserName);

            docuTable.CompanyTableId            = user.CompanyTableId;
            docuTable.ApplicationUserCreatedId  = user.Id;
            docuTable.ApplicationUserModifiedId = user.Id;

            EmplTable emplTable = _EmplService.FirstOrDefault(x => x.ApplicationUserId == user.Id);

            docuTable.EmplTableId = emplTable.Id;

            Guid numberSeqId = _ProcessService.Find(processId).GroupProcessTable.NumberSeriesTableId ?? Guid.Empty;

            docuTable.DocumentNum = _NumberSeqService.GetDocumentNum(numberSeqId);
            _uow.GetRepository <DocumentTable>().Add(docuTable);
            _uow.Save();

            var domainTable = RouteCustomModelDomain(tableName);

            Mapper.Map(viewTable, domainTable);
            domainTable.DocumentTableId = docuTable.Id;
            domainTable.CreatedDate     = DateTime.UtcNow;
            domainTable.ModifiedDate    = domainTable.CreatedDate;
            RouteCustomRepository(tableName).Add(domainTable);
            _uow.Save();

            docuTable.RefDocumentId = domainTable.Id;
            _uow.GetRepository <DocumentTable>().Update(docuTable);
            _uow.Save();

            return(docuTable.Id);
        }
Пример #29
0
        public void FindColumnTypeChange()
        {
            var table = new DocumentTable("Entities");

            table.Register(new Column("Number", typeof(int)));
            schema.Add(table);

            configuration.Document <Entity>().With("Number", x => x.String);

            var commands = migrator.CalculateSchemaChanges(schema, configuration).ToList();

            commands[0].ShouldBeOfType <AddColumn>()
            .Tablename.ShouldBe(GetTableFor <Entity>().Name);
            ((AddColumn)commands[0]).Column.ShouldBe(GetTableFor <Entity>()["Number"]);

            commands[1].ShouldBeOfType <RemoveColumn>()
            .Table.ShouldBe(GetTableFor <Entity>());
            ((RemoveColumn)commands[1]).Name.ShouldBe("Number");
        }
Пример #30
0
        public DocumentSchema(DocumentMapping mapping)
        {
            _mapping = mapping;

            Table = new DocumentTable(_mapping);

            foreach (var metadataColumn in Table.Columns.OfType <MetadataColumn>())
            {
                metadataColumn.RegisterForLinqSearching(mapping);
            }

            Upsert = new UpsertFunction(_mapping);
            Insert = new InsertFunction(_mapping);
            Update = new UpdateFunction(_mapping);

            if (_mapping.UseOptimisticConcurrency)
            {
                Overwrite = new OverwriteFunction(_mapping);
            }
        }