本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}