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


C# ModelBuilder.AddDateTime方法代码示例

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


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

示例1: EnsureCreatedOn

 private void EnsureCreatedOn(EntityModel em)
 {
     var createdOn = em.Properties[Properties.CreatedOn];
     if (createdOn == null)
     {
         var mb = new ModelBuilder(em);
         mb.AddDateTime(Properties.CreatedOn);
         //mb.Rules.AddRequired(Properties.CreatedOn);//TODO-History: make createdon not null
     }
     else if (createdOn.Type != PropertyType.Datetime || createdOn.DefaultValue != null)
         throw new NotSupportedException(string.Format("Entity <{0}> contains property <{1}> which is system for the HistoryModule.", em.Name, createdOn.Name));
 }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:12,代码来源:HistoryModule.cs

示例2: BeforeSave

            public void BeforeSave(EntityModel entityModel)
            {
                if (entityModel.IsNomenclature)
                    return;

                if (!entityModel.Properties.Contains("CreatedOn"))
                {
                    var mb = new ModelBuilder(entityModel);
                    mb.AddDateTime("CreatedOn");
                }
            }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:11,代码来源:EntityTests.cs

示例3: 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");

            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);

            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");
            dm.Entities.Add(bo.EntityModel);

            dms.Save(dm);
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:37,代码来源:EntityTests.cs

示例4: Test_ModelBuilder_BuildModel_General

        public void Test_ModelBuilder_BuildModel_General()
        {
            ModelBuilder b = new ModelBuilder("Author");
            b.AddString("FirstName", 128);
            b.AddString("LastName", 128);
            b.AddBoolean("IsAlive", true);
            b.AddInteger("NumberOfAwards");
            b.AddDateTime("Born");
            b.AddDecimal("Rating");

            var em = b.EntityModel;
            Assert.IsNotNull(em);

            //string prop
            var fname = em.Properties["firstNAME"];
            Assert.IsTrue(fname is StringPropertyModel);
            Assert.AreEqual(128, (fname as StringPropertyModel).Length);

            //boolean prop
            var isalive = em.Properties["isalive"];
            Assert.IsTrue(isalive is BooleanPropertyModel);
            Assert.AreEqual(true, isalive.DefaultValue);

            //integer prop
            var noa = em.Properties["numberofawards"];
            Assert.IsTrue(noa is NumberPropertyModel);
            Assert.AreEqual(true, (noa as NumberPropertyModel).IsInteger);

            //datetime prop
            var born = em.Properties["born"];
            Assert.IsTrue(born is DateTimePropertyModel);
            //TODO: more testing datetime prop building

            //decimal prop
            var rating = em.Properties["rating"];
            Assert.IsTrue(rating is NumberPropertyModel);
            Assert.AreEqual(false, (rating as NumberPropertyModel).IsInteger);
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:38,代码来源:EntityTests.cs

示例5: 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

示例6: Test_DomainModelService_Union

        public void Test_DomainModelService_Union()
        {
            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");

            ModelBuilder bb = new ModelBuilder("Book");
            bb.AddIdentity("Id");
            bb.AddString("Title", 256);
            bb.AddString("ISBN", 20);

            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);

            ModelBuilder bo = new ModelBuilder("Order");
            bo.AddDecimal("Total");
            bo.AddBoolean("Paid");
            bo.AddDateTime("CreatedOn");
            bo.AddDateTime("ShipmentDate");

            ModelBuilder bb2 = new ModelBuilder("Book");
            bb2.AddIdentity("Id");
            bb2.AddString("Title", 256);
            bb2.AddString("Barcode", 20);
            bb2.AddDecimal("Price");

            bo.AddRelationTo(bb2.EntityModel, RelationType.ManyToMany, "Ordered");

            var dm2 = new DomainModel();
            dm2.Entities.Add(bo.EntityModel);
            dm2.Entities.Add(bb2.EntityModel);

            var un = svc.Union(new DomainModel[] { dm, dm2 });

            Assert.AreEqual(3, un.Entities.Count);
            var author = un.Entities["author"];
            Assert.AreEqual(8, author.Properties.Count);
            Assert.AreEqual(5, un.Entities["book"].Properties.Count);
            Assert.AreEqual(4, un.Entities["Order"].Properties.Count);
            Assert.AreEqual(2, un.Relations.Count);
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:53,代码来源:EntityTests.cs

示例7: Test_DomainModelService_Merge

        public void Test_DomainModelService_Merge()
        {
            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");

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

            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);

            svc.Save(dm);
            using (var conn = new TestDatabaseService().GetSqlConnection())
            {
                conn.Open();
                DatabaseManager dbm = new DatabaseManager(conn);
                dbm.LoadSchema();
                var tableA = dbm.Tables.Find(t => t.Name == "Author");
                Assert.IsNotNull(tableA);
                var fnCol = tableA.Columns.Find(c => c.Name.Equals("FullName", StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(fnCol);
            }

            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");
            dm.Entities.Add(bo.EntityModel);

            ba.EntityModel.Properties.Remove(ba.EntityModel.Properties["IsAlive"]);
            (ba.EntityModel.Properties["LastName"] as StringPropertyModel).Length = 256;
            (ba.EntityModel.Properties["firstName"] as StringPropertyModel).Length = 256;
            (bb.EntityModel.Properties["genre"] as EnumPropertyModel).DefaultValue = Genre.Horror;
            ba.AddString("Nickname", 256);

            svc.Merge(dm);

            Assert.AreEqual(3, svc.Domain.Entities.Count);
            //foreach (var em1 in dm.Entities)
            //{
            //    var em2 = svc.Domain.Entities[em1.Name];
            //    Assert.AreEqual(em1.Properties.Count, em2.Properties.Count);
            //}
            //TODO-tests:finish domainmodelservice_merge test

            //Computed columns are droped and recreated when upgrading the columns in their computed definition
            using (var conn = new TestDatabaseService().GetSqlConnection())
            {
                conn.Open();
                DatabaseManager dbm = new DatabaseManager(conn);
                dbm.LoadSchema();
                var tableA = dbm.Tables.Find(t => t.Name == "Author");
                Assert.IsNotNull(tableA);
                var fnCol = tableA.Columns.Find(c => c.Name.Equals("FullName", StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(fnCol);
            }
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:76,代码来源:EntityTests.cs

示例8: Test_DomainModelService_Compare

        public void Test_DomainModelService_Compare()
        {
            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", false);
            ba.AddInteger("NumberOfAwards");
            ba.AddDateTime("Born");
            ba.AddDecimal("Rating");
            ba.AddString("Uri", 20);

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

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

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

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

            svc.Save(dm);

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

            ba.EntityModel.Properties.Remove(ba.EntityModel.Properties["IsAlive"]);
            (ba.EntityModel.Properties["LastName"] as StringPropertyModel).Length = 256;
            (ba.EntityModel.Properties["firstName"] as StringPropertyModel).Length = 256;
            ba.AddString("Nickname", 256);
            ba.Rules.AddUnique("Uri");
            (ba.EntityModel.Properties["Rating"] as NumberPropertyModel).DefaultValue = 5.0m;

            DomainModelChanges dmc = svc.CompareWithExisting(dm);
            Assert.AreEqual(2, dmc.EntityChanges.Count());
            Assert.AreEqual(1, dmc.EntityChanges.Count(ec => ec.Change == ChangeType.Created));
            var ecs = dmc.EntityChanges.Single(ec => ec.Change == ChangeType.Created);
            Assert.AreEqual(bo.EntityModel.Properties.Count, ecs.PropertyChanges.Count());
            Assert.AreEqual(1, dmc.EntityChanges.Count(ec => ec.Change == ChangeType.Modified));

            Assert.AreEqual(1, dmc.RelationChanges.Count());

            var change = dmc.EntityChanges.Single(e => e.New.Name == ba.EntityModel.Name);
            Assert.AreEqual(5, change.PropertyChanges.Count());
            Assert.AreEqual(3, change.PropertyChanges.Count(pc => pc.Change == ChangeType.Modified));
            Assert.AreEqual(1, change.PropertyChanges.Count(pc => pc.Change == ChangeType.Deleted));
            Assert.AreEqual(1, change.PropertyChanges.Count(pc => pc.Change == ChangeType.Created));
            Assert.AreEqual(1, change.RuleChanges.Count());
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:62,代码来源:EntityTests.cs

示例9: Test_DomainModelService_Basic

        public void Test_DomainModelService_Basic()
        {
            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.Rules.AddRequired("title");
            bb.Rules.AddUnique("ISBN");

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

            svc.Save(dm);

            Assert.IsNotNull(svc.Domain);
            Assert.IsNotNull(svc.Domain.Entities["author"]);
            Assert.IsNotNull(svc.Domain.Entities["book"]);
            Assert.IsNotNull(svc.Domain.Relations["book", "author", "author"]);
        }
开发者ID:kvuchkov,项目名称:nbulib,代码行数:36,代码来源:EntityTests.cs


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