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


C# SimpleModelContext.Set方法代码示例

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


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

示例1: Set_method_returns_the_same_instance_each_invocation

        public void Set_method_returns_the_same_instance_each_invocation()
        {
            using (var context = new SimpleModelContext())
            {
                var set1 = context.Set<Product>();
                var set2 = context.Set<Product>();

                Assert.Same(set1, set2);
                Assert.Same(set1, context.Products);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:11,代码来源:DbContextTests.cs

示例2: Non_generic_Set_method_returns_the_same_instance_each_invocation

        public void Non_generic_Set_method_returns_the_same_instance_each_invocation()
        {
            using (var context = new SimpleModelContext())
            {
                var set1 = context.Set(typeof(Product));
                var set2 = context.Set(typeof(Product));

                Assert.Same(set1, set2);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:10,代码来源:DbContextTests.cs

示例3: Can_create_DbSet_for_derived_type

        public void Can_create_DbSet_for_derived_type()
        {
            using (var context = new SimpleModelContext())
            {
                var set = context.Set<FeaturedProduct>();
                Assert.IsType<DbSet<FeaturedProduct>>(set);

                var entity = set.FirstOrDefault();
                Assert.IsType<FeaturedProduct>(entity);
                Assert.Equal(EntityState.Unchanged, GetStateEntry(context, entity).State);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:12,代码来源:DbContextTests.cs

示例4: Can_create_non_generic_DbSet_for_derived_type

        public void Can_create_non_generic_DbSet_for_derived_type()
        {
            using (var context = new SimpleModelContext())
            {
                var set = context.Set(typeof(FeaturedProduct));
                Assert.Equal(typeof(FeaturedProduct), set.ElementType);

                var entity = set.Cast<FeaturedProduct>().FirstOrDefault();
                Assert.IsType<FeaturedProduct>(entity);
                Assert.Equal(EntityState.Unchanged, GetStateEntry(context, entity).State);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:12,代码来源:DbContextTests.cs

示例5: Can_create_non_generic_DbSet_for_base_type

        public void Can_create_non_generic_DbSet_for_base_type()
        {
            using (var context = new SimpleModelContext())
            {
                var set = context.Set(typeof(Product));
                Assert.Equal(typeof(Product), set.ElementType);

                var entity = set.Cast<Product>().FirstOrDefault();
                Assert.IsType<Product>(entity);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:11,代码来源:DbContextTests.cs

示例6: Can_create_DbSet_for_base_type

        public void Can_create_DbSet_for_base_type()
        {
            using (var context = new SimpleModelContext())
            {
                var set = context.Set<Product>();
                Assert.IsType<DbSet<Product>>(set);

                var entity = set.FirstOrDefault();
                Assert.IsType<Product>(entity);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:11,代码来源:DbContextTests.cs

示例7: Can_create_non_generic_DbSet

        public void Can_create_non_generic_DbSet()
        {
            using (var context = new SimpleModelContext())
            {
                var set = context.Set(typeof(Category));
                Assert.Equal(typeof(Category), set.ElementType);

                var entity = set.Cast<Category>().FirstOrDefault();
                Assert.IsType<Category>(entity);
                Assert.Equal(EntityState.Unchanged, GetStateEntry(context, entity).State);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:12,代码来源:DbContextTests.cs

示例8: Can_create_DbSet

        public void Can_create_DbSet()
        {
            using (var context = new SimpleModelContext())
            {
                var set = context.Set<Category>();
                Assert.IsType<DbSet<Category>>(set);

                var entity = set.FirstOrDefault();
                Assert.IsType<Category>(entity);
                Assert.Equal(EntityState.Unchanged, GetStateEntry(context, entity).State);
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:12,代码来源:DbContextTests.cs

示例9: Sets_of_subtypes_can_still_be_sorted

        public void Sets_of_subtypes_can_still_be_sorted()
        {
            using (var context = new SimpleModelContext())
            {
                var featuredProducts = context.Set<FeaturedProduct>();
                featuredProducts.Attach(
                    new FeaturedProduct
                        {
                            Id = 3
                        });
                featuredProducts.Attach(
                    new FeaturedProduct
                        {
                            Id = 1
                        });
                featuredProducts.Attach(
                    new FeaturedProduct
                        {
                            Id = 4
                        });

                var bindingList = featuredProducts.Local.ToBindingList();

                ((IBindingList)bindingList).ApplySort(
                    TypeDescriptor.GetProperties(typeof(Product))["Id"],
                    ListSortDirection.Ascending);

                Assert.Equal(1, bindingList[0].Id);
                Assert.Equal(3, bindingList[1].Id);
                Assert.Equal(4, bindingList[2].Id);
            }
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:32,代码来源:DatabindingTests.cs


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