本文整理汇总了C#中IDbContextFactory.GetContext方法的典型用法代码示例。如果您正苦于以下问题:C# IDbContextFactory.GetContext方法的具体用法?C# IDbContextFactory.GetContext怎么用?C# IDbContextFactory.GetContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbContextFactory
的用法示例。
在下文中一共展示了IDbContextFactory.GetContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCustomerCreation
public void TestCustomerCreation()
{
//Creating customer
var Customer = new Customer() { CustomerName = "Customer 1", Telephome = "78-676-121212", Sites = new List<Site>() };
Customer.Sites.Add(new Site() { Address = "Site 1", PostCode = "001", SiteNumber = "ST01" });
Customer.Sites.Add(new Site() { Address = "Site 2", PostCode = "002", SiteNumber = "ST02" });
iocCtxFactory = iocContainer.Resolve<IDbContextFactory>();
var iocDBContext = iocCtxFactory.GetContext();
//adding customer to database
var sotredCustomer = iocDBContext.Set<Customer>().Add(Customer);
iocDBContext.SaveChanges();
var customerId = sotredCustomer.Id;
//Test
var nonIoCContext = new DbContextFactory().GetContext();
var customerFrom_IOC_Context = iocCtxFactory.GetContext().Set<Customer>().Where(c => c.Id == customerId).SingleOrDefault();
var customerNon_IOC_Context = nonIoCContext.Set<Customer>().Where(c => c.Id == customerId).SingleOrDefault();
Assert.IsNull(customerNon_IOC_Context.Sites);
//Expecting empty but having values if IOC lifestyle is singleton or PerWebRequest :(
//transient is working as expected
Assert.IsNull(customerFrom_IOC_Context.Sites);
}
示例2: EventLogger
public EventLogger(IDbContextFactory dbContextFactory)
{
var dbContext = dbContextFactory.GetContext();
_dbPackageEventSet = dbContext.Set<PackageEvent>();
_dbSchedulerEventSet = dbContext.Set<SchedulerEvent>();
_dbServerEventSet = dbContext.Set<ServerEvent>();
_dbSystemEventSet = dbContext.Set<SystemEvent>();
_dbServerDeploymentEventSet = dbContext.Set<ServerDeploymentEvent>();
_dbNotificationSet = dbContext.Set<Notification>();
_dbNotificationTypeSet = dbContext.Set<NotificationType>();
intNotificationTypeID = FindNotificationType("MindAlign");
}
示例3: BeforeTest
public void BeforeTest()
{
Database.SetInitializer(new DropCreateDatabaseAlways<EasyReadDbContext>());
_contextFactory = new TestContextFactory(new EasyReadDbContext("DefaultContext"));
_contextFactory.GetContext().Database.Initialize(true);
}
示例4: UsageLogger
public UsageLogger(IDbContextFactory dbContextFactory)
{
var dbContext = dbContextFactory.GetContext();
_dbUsageSet = dbContext.Set<Usage>();
}
示例5: PostRepository
public PostRepository(IDbContextFactory contextFactory)
{
_context = contextFactory.GetContext();
}
示例6: PostsRepository
public PostsRepository(IDbContextFactory dbContextFactory)
{
DbContext = dbContextFactory.GetContext();
DbSet = DbContext.Set<Post>();
}
示例7: UnitOfWork
public UnitOfWork(IDbContextFactory dbContextFactory)
{
_dbContext = dbContextFactory.GetContext();
}
示例8: CategoriesRepository
public CategoriesRepository(IDbContextFactory dbContextFactory)
{
DbContext = dbContextFactory.GetContext();
DbSet = DbContext.Set<Category>();
}
示例9: UserCredential
public UserCredential(IDbContextFactory dbContextFactory)
{
var dbContext = dbContextFactory.GetContext();
_dbAdGroupSet = dbContext.Set<ADGroup>();
}