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


C# EarlyLearningCenter.Add方法代码示例

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


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

示例1: Can_get_all_entries

        public void Can_get_all_entries()
        {
            using (var context = new EarlyLearningCenter())
            {
                var category = context.Add(new Category()).Entity;
                var product = context.Add(new Product()).Entity;

                Assert.Equal(
                    new object[] { category, product },
                    context.ChangeTracker.Entries().Select(e => e.Entity).OrderBy(e => e.GetType().Name));
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:12,代码来源:ChangeTrackerTest.cs

示例2: Members_check_arguments

 public void Members_check_arguments()
 {
     using (var context = new EarlyLearningCenter())
     {
         Assert.Equal(
             "entity",
             // ReSharper disable once AssignNullToNotNullAttribute
             Assert.Throws<ArgumentNullException>(() => context.Add<Random>(null)).ParamName);
         Assert.Equal(
             "entity",
             // ReSharper disable once AssignNullToNotNullAttribute
             Assert.ThrowsAsync<ArgumentNullException>(() => context.AddAsync<Random>(null)).Result.ParamName);
         Assert.Equal(
             "entity",
             // ReSharper disable once AssignNullToNotNullAttribute
             Assert.Throws<ArgumentNullException>(
                 () => context.AddAsync<Random>(null, new CancellationToken()).GetAwaiter().GetResult()).ParamName);
         Assert.Equal(
             "entity",
             // ReSharper disable once AssignNullToNotNullAttribute
             Assert.Throws<ArgumentNullException>(() => context.Update<Random>(null)).ParamName);
         Assert.Equal(
             "entity",
             // ReSharper disable once AssignNullToNotNullAttribute
             Assert.ThrowsAsync<ArgumentNullException>(() => context.UpdateAsync<Random>(null)).Result.ParamName);
         Assert.Equal(
             "entity",
             // ReSharper disable once AssignNullToNotNullAttribute
             Assert.ThrowsAsync<ArgumentNullException>(() => context.UpdateAsync<Random>(null, new CancellationToken())).Result.ParamName);
     }
 }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:31,代码来源:DbContextTest.cs

示例3: Can_add_identifying_one_to_many_via_dependents_with_key_generation

        [Fact] // Issue #1207
        public void Can_add_identifying_one_to_many_via_dependents_with_key_generation()
        {
            using (var context = new EarlyLearningCenter())
            {
                var product1 = new Product();
                var product2 = new Product();

                var order1 = new Order();
                var order2 = new Order();

                var orderDetails1a = new OrderDetails { Order = order1, Product = product1 };
                var orderDetails1b = new OrderDetails { Order = order1, Product = product2 };
                var orderDetails2a = new OrderDetails { Order = order2, Product = product1 };
                var orderDetails2b = new OrderDetails { Order = order2, Product = product2 };

                context.Add(orderDetails1a);
                context.Add(orderDetails2a);
                context.Add(orderDetails1b);
                context.Add(orderDetails2b);
                context.Add(order1);
                context.Add(product1);
                context.Add(order2);
                context.Add(product2);

                AssertOrderAndDetailsFixedUp(context, orderDetails1a, orderDetails1b, orderDetails2a, orderDetails2b);
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:28,代码来源:ChangeTrackerTest.cs

示例4: Can_add_identifying_dependents_and_principal_with_reverse_post_nav_fixup_with_key_generation

        [Fact] // Issue #1207
        public void Can_add_identifying_dependents_and_principal_with_reverse_post_nav_fixup_with_key_generation()
        {
            using (var context = new EarlyLearningCenter())
            {
                var product1 = new Product();
                var details1 = new ProductDetails();
                var tag1 = new ProductDetailsTag();
                var tagDetails1 = new ProductDetailsTagDetails();

                var product2 = new Product();
                var details2 = new ProductDetails();
                var tag2 = new ProductDetailsTag();
                var tagDetails2 = new ProductDetailsTagDetails();

                context.Add(product1);
                context.Add(tagDetails2);
                context.Add(details1);
                context.Add(tag2);
                context.Add(details2);
                context.Add(tag1);
                context.Add(tagDetails1);
                context.Add(product2);

                tagDetails1.Tag = tag1;
                tag1.Details = details1;
                details1.Product = product1;

                tagDetails2.Tag = tag2;
                tag2.Details = details2;
                details2.Product = product2;

                context.ChangeTracker.DetectChanges();

                AssertProductAndDetailsFixedUp(context, product1.Details.Tag.TagDetails, product2.Details.Tag.TagDetails);
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:37,代码来源:ChangeTrackerTest.cs

示例5: Can_add_principal_and_identifying_dependents_starting_in_the_middle_with_key_generation

        [Fact] // Issue #1207
        public void Can_add_principal_and_identifying_dependents_starting_in_the_middle_with_key_generation()
        {
            using (var context = new EarlyLearningCenter())
            {
                var product1 = new Product
                    {
                        Details = new ProductDetails
                            {
                                Tag = new ProductDetailsTag
                                    {
                                        TagDetails = new ProductDetailsTagDetails()
                                    }
                            }
                    };
                var product2 = new Product
                    {
                        Details = new ProductDetails
                            {
                                Tag = new ProductDetailsTag
                                    {
                                        TagDetails = new ProductDetailsTagDetails()
                                    }
                            }
                    };

                context.Add(product1.Details);
                context.Add(product2.Details);
                context.Add(product1.Details.Tag.TagDetails);
                context.Add(product1);
                context.Add(product1.Details.Tag);
                context.Add(product2.Details.Tag);
                context.Add(product2.Details.Tag.TagDetails);
                context.Add(product2);

                AssertProductAndDetailsFixedUp(context, product1.Details.Tag.TagDetails, product2.Details.Tag.TagDetails);
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:38,代码来源:ChangeTrackerTest.cs

示例6: Can_add_identifying_dependents_and_principal_starting_in_the_middle_with_key_generation

        [Fact] // Issue #1207
        public void Can_add_identifying_dependents_and_principal_starting_in_the_middle_with_key_generation()
        {
            using (var context = new EarlyLearningCenter())
            {
                var tagDetails1 = new ProductDetailsTagDetails
                    {
                        Tag = new ProductDetailsTag
                            {
                                Details = new ProductDetails
                                    { Product = new Product() }
                            }
                    };

                var tagDetails2 = new ProductDetailsTagDetails
                    {
                        Tag = new ProductDetailsTag
                            {
                                Details = new ProductDetails
                                    { Product = new Product() }
                            }
                    };

                context.Add(tagDetails1.Tag);
                context.Add(tagDetails2.Tag);
                context.Add(tagDetails1);
                context.Add(tagDetails2);
                context.Add(tagDetails2.Tag.Details);
                context.Add(tagDetails1.Tag.Details);
                context.Add(tagDetails1.Tag.Details.Product);
                context.Add(tagDetails2.Tag.Details.Product);

                AssertProductAndDetailsFixedUp(context, tagDetails1, tagDetails2);
            }
        }
开发者ID:aishaloshik,项目名称:EntityFramework,代码行数:35,代码来源:ChangeTrackerTest.cs

示例7: Throws_when_instance_of_unmapped_derived_type_is_used

 [Fact] // Issue #743
 public void Throws_when_instance_of_unmapped_derived_type_is_used()
 {
     using (var context = new EarlyLearningCenter())
     {
         Assert.Equal(CoreStrings.EntityTypeNotFound(typeof(SpecialProduct).Name),
             Assert.Throws<InvalidOperationException>(() => context.Add(new SpecialProduct())).Message);
     }
 }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:9,代码来源:ChangeTrackerTest.cs


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