当前位置: 首页>>代码示例>>C#>>正文


C# DatabaseTable.AddConstraint方法代码示例

本文整理汇总了C#中DatabaseSchemaReader.DataSchema.DatabaseTable.AddConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseTable.AddConstraint方法的具体用法?C# DatabaseTable.AddConstraint怎么用?C# DatabaseTable.AddConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseSchemaReader.DataSchema.DatabaseTable的用法示例。


在下文中一共展示了DatabaseTable.AddConstraint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WithBidirectionalDepndencyTopologicalSort

        public void WithBidirectionalDepndencyTopologicalSort()
        {
            //arrange
            var schema = new DatabaseSchema(null, null);

            var orders = new DatabaseTable();
            orders.Name = "countries";
            var productsFk = new DatabaseConstraint();
            productsFk.ConstraintType = ConstraintType.ForeignKey;
            productsFk.RefersToTable = "capitalcities";
            orders.AddConstraint(productsFk);
            schema.Tables.Add(orders);

            var products = new DatabaseTable();
            products.Name = "capitalcities";
            var categoriesFk = new DatabaseConstraint();
            categoriesFk.ConstraintType = ConstraintType.ForeignKey;
            categoriesFk.RefersToTable = "countries";
            products.AddConstraint(categoriesFk);
            schema.Tables.Add(products);

            //a country has one capital city
            //a capital city is in one country
            //But bidirectional foreign keys is terrible database design - you really only need one direction.
            //(you have to save the country with a null capital, then the capital, then update the country again).
            //Topological sorts don't support cycles, so we should just get back the original list

            //act
            var sortedTables = SchemaTablesSorter.TopologicalSort(schema);

            //assert
            Assert.AreEqual(2, sortedTables.Count());
            //non-deterministic order
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:34,代码来源:SchemaTablesSorterTest.cs

示例2: TestSqlServerCheckConstraint

        public void TestSqlServerCheckConstraint()
        {
            //arrange
            var table = new DatabaseTable {Name = "Orders"};

            var check = new DatabaseConstraint
                            {
                                ConstraintType = ConstraintType.Check,
                                Expression = "[Quantity] > 0",
                                Name = "ValidationRule"
                            };

            table.AddConstraint(check);

            var writer = new ConstraintWriter(table);

            //act
            var txt = writer.WriteCheckConstraints();

            //assert
            Assert.IsTrue(txt.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [ValidationRule] CHECK ([Quantity] > 0);"));
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:22,代码来源:AccessCheckConstraintTest.cs

示例3: TestAccessDateCheckConstraint

        public void TestAccessDateCheckConstraint()
        {
            //arrange
            var table = new DatabaseTable {Name = "Orders"};

            var check = new DatabaseConstraint
                            {
                                ConstraintType = ConstraintType.Check,
                                Expression = ">Date()",
                                Name = "[Orders].[OrderDate].ValidationRule"
                            };

            table.AddConstraint(check);

            var writer = new TableGenerator(table);

            //act
            var txt = writer.Write();

            //assert
            Assert.IsTrue(txt.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [Orders_OrderDate_ValidationRule] CHECK ([Orders].[OrderDate] >getdate());"));
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:22,代码来源:AccessCheckConstraintTest.cs

示例4: TestTopologicalSort

        public void TestTopologicalSort()
        {
            //arrange
            var schema = new DatabaseSchema(null, null);

            var orders = new DatabaseTable();
            orders.Name = "orders";
            var productsFk = new DatabaseConstraint
                                 {
                                     ConstraintType = ConstraintType.ForeignKey,
                                     RefersToTable = "products"
                                 };
            orders.AddConstraint(productsFk);
            schema.Tables.Add(orders);

            var categories = new DatabaseTable();
            categories.Name = "categories";
            schema.Tables.Add(categories);

            var products = new DatabaseTable();
            products.Name = "products";
            var categoriesFk = new DatabaseConstraint();
            categoriesFk.ConstraintType = ConstraintType.ForeignKey;
            categoriesFk.RefersToTable = "categories";
            products.AddConstraint(categoriesFk);
            schema.Tables.Add(products);

            //act
            var sortedTables = SchemaTablesSorter.TopologicalSort(schema);

            //assert
            var first = sortedTables.First();
            var last = sortedTables.Last();
            Assert.AreEqual(categories, first);
            Assert.AreEqual(orders, last);
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:36,代码来源:SchemaTablesSorterTest.cs


注:本文中的DatabaseSchemaReader.DataSchema.DatabaseTable.AddConstraint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。