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


C# ModelBuilder.AddUri方法代码示例

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


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

示例1: Test_DomainModelSerializer

        public void Test_DomainModelSerializer()
        {
            var dm = new DomainModel();
            ModelBuilder ba = new ModelBuilder("Author");
            ba.AddIdentity("Id");
            ba.AddString("FirstName", 128);
            ba.AddString("LastName", 128);
            ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
            ba.AddBoolean("IsAlive", true);
            ba.AddInteger("NumberOfAwards");
            ba.AddDateTime("Born");
            ba.AddDecimal("Rating");

            ba.EntityModel.Rules.Add(new FutureOrPastDateRuleModel((DateTimePropertyModel)ba.EntityModel.Properties["born"], TimeSpan.Zero, false));

            ModelBuilder bb = new ModelBuilder("Book");
            bb.AddIdentity("Id");
            bb.AddString("Title", 256);
            bb.AddString("ISBN", 20);
            bb.AddDecimal("Price");
            bb.AddEnum<Genre>("Genre");
            bb.AddUri("BookUri", "books");

            bb.Rules.AddRequired("title");
            bb.Rules.AddUnique("ISBN");

            ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");

            dm.Entities.Add(ba.EntityModel);
            dm.Entities.Add(bb.EntityModel);
            dm.Relations.Add(ba.EntityModel.Relations.Single());
            ModelBuilder mbRel = new ModelBuilder(ba.EntityModel.Relations.Single());
            mbRel.AddIdentity("id");
            mbRel.AddIdentity("rid");
            mbRel.AddIdentity("lid");
            mbRel.Rules.AddRequired("lid");
            mbRel.Rules.AddRequired("rid");

            DomainModelSerializer ser = new DomainModelSerializer();
            XmlDocument xmlDoc = ser.Serialize(dm);
            var dm2 = ser.Deserialize(xmlDoc);

            Assert.AreEqual(dm.Entities.Count, dm2.Entities.Count);
            Assert.AreEqual(dm.Relations.Count, dm2.Relations.Count);
            var en1 = dm.Entities.GetEnumerator();
            var en2 = dm2.Entities.GetEnumerator();
            while (en1.MoveNext() && en2.MoveNext())
            {
                Assert.AreEqual(en1.Current.Name, en2.Current.Name);
                Assert.AreEqual(en1.Current.Properties.Count, en2.Current.Properties.Count);
                Assert.AreEqual(en1.Current.Relations.Count, en2.Current.Relations.Count);
                Assert.AreEqual(en1.Current.Rules.Count, en2.Current.Rules.Count);
                var p1 = en1.Current.Properties.GetEnumerator();
                var p2 = en2.Current.Properties.GetEnumerator();
                while (p1.MoveNext() && p2.MoveNext())
                {
                    Assert.AreEqual(p1.Current.Name, p2.Current.Name);
                    Assert.AreEqual(p1.Current.Type, p2.Current.Type);
                    Assert.AreEqual(p1.Current.DefaultValue, p2.Current.DefaultValue);
                    Assert.AreEqual(p1.Current.GetType(), p2.Current.GetType());
                    if (p1.Current.Type == PropertyType.Enum)
                        Assert.AreEqual(((EnumPropertyModel)p1.Current).EnumType, ((EnumPropertyModel)p2.Current).EnumType);
                    else if (p1.Current.Type == PropertyType.Computed)
                        Assert.AreEqual(((ComputedPropertyModel)p1.Current).Formula, ((ComputedPropertyModel)p2.Current).Formula);
                    else if (p1.Current.Type == PropertyType.Number)
                        Assert.AreEqual(((NumberPropertyModel)p1.Current).IsInteger, ((NumberPropertyModel)p2.Current).IsInteger);
                    else if (p1.Current.Type == PropertyType.Sequence)
                    {
                        Assert.AreEqual(((SequencePropertyModel)p1.Current).SequenceType, ((SequencePropertyModel)p2.Current).SequenceType);
                        Assert.AreEqual(((SequencePropertyModel)p1.Current).SequenceId, ((SequencePropertyModel)p2.Current).SequenceId);
                    }
                }

                var r1 = en1.Current.Rules.GetEnumerator();
                var r2 = en2.Current.Rules.GetEnumerator();
                while (r1.MoveNext() && r2.MoveNext())
                {
                    Assert.AreEqual(r1.Current.GetType(), r2.Current.GetType());
                    if (r1.Current is RequiredRuleModel)
                        Assert.AreEqual((r1.Current as RequiredRuleModel).Property.Name, (r2.Current as RequiredRuleModel).Property.Name);
                    else if (r1.Current is UniqueRuleModel)
                    {
                        Assert.AreEqual((r1.Current as UniqueRuleModel).Properties.Count(), (r2.Current as UniqueRuleModel).Properties.Count());
                        var pren1 = (r1.Current as UniqueRuleModel).Properties.GetEnumerator();
                        var pren2 = (r2.Current as UniqueRuleModel).Properties.GetEnumerator();
                        while (pren1.MoveNext() && pren2.MoveNext())
                        {
                            Assert.AreEqual(pren1.Current.Name, pren2.Current.Name);
                        }
                    }
                    else if (r1.Current is FutureOrPastDateRuleModel)
                    {
                        var er1 = r1.Current as FutureOrPastDateRuleModel;
                        var er2 = r2.Current as FutureOrPastDateRuleModel;
                        Assert.AreEqual(er1.Future, er2.Future);
                        Assert.AreEqual(er1.Offset, er2.Offset);
                        Assert.AreEqual(er1.Property.Name, er2.Property.Name);
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:kvuchkov,项目名称:nbulib,代码行数:101,代码来源:EntityTests.cs

示例2: CreateDomain

        private static void CreateDomain()
        {
            var dm = new DomainModel();
            ModelBuilder ba = new ModelBuilder("Author");
            ba.AddIdentity("Id");
            ba.AddString("FirstName", 128);
            ba.AddString("LastName", 128);
            ba.AddBoolean("IsAlive", true);
            ba.AddInteger("NumberOfAwards");
            ba.AddDateTime("Born");
            ba.AddDecimal("Rating");

            ModelBuilder bb = new ModelBuilder("Book");
            bb.AddIdentity("Id");
            bb.AddString("Title", 256);
            bb.AddString("ISBN", 20);
            bb.AddDecimal("Price");
            bb.AddEnum<Genre>("Genre", Genre.Mistery);

            bb.Rules.AddRequired("title");
            bb.Rules.AddUnique("ISBN");

            var rel = ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
            var br = new ModelBuilder(rel);
            br.AddDateTime("WrittenOn");

            dm.Entities.Add(ba.EntityModel);
            dm.Entities.Add(bb.EntityModel);

            ModelBuilder bo = new ModelBuilder("Order");
            bo.AddDecimal("Total");
            bo.AddBoolean("Paid");
            bo.AddDateTime("CreatedOn");
            bo.AddDateTime("ShipmentDate");
            bo.AddRelationTo(dm.Entities["book"], RelationType.ManyToMany, "Ordered");
            bo.AddUri("Number", "BO");
            dm.Entities.Add(bo.EntityModel);

            dms.Save(dm);

            using (var conn = new TestDatabaseService().GetSqlConnection())
            {
                conn.Open();
                var dbManager = new DatabaseManager(conn);
                SequenceProvider.Initialize(dbManager);
            }
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:47,代码来源:EntityTests.cs


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