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


C# IDbContextFactory.GetContext方法代码示例

本文整理汇总了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);
        }
开发者ID:jithGit,项目名称:EFTDataAccess,代码行数:29,代码来源:IntegrationTest.cs

示例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");
        }
开发者ID:sap-sh,项目名称:t,代码行数:13,代码来源:EventLogger.cs

示例3: BeforeTest

 public void BeforeTest()
 {
     Database.SetInitializer(new DropCreateDatabaseAlways<EasyReadDbContext>());
     _contextFactory = new TestContextFactory(new EasyReadDbContext("DefaultContext"));
     _contextFactory.GetContext().Database.Initialize(true);
 }
开发者ID:eugene-blokhin,项目名称:EasyRead,代码行数:6,代码来源:LoginAuthenticationRepositoryTests.cs

示例4: UsageLogger

 public UsageLogger(IDbContextFactory dbContextFactory)
 {
     var dbContext = dbContextFactory.GetContext();
     _dbUsageSet = dbContext.Set<Usage>();
 }
开发者ID:sap-sh,项目名称:t,代码行数:5,代码来源:UsageLogger.cs

示例5: PostRepository

 public PostRepository(IDbContextFactory contextFactory)
 {
     _context = contextFactory.GetContext();
 }
开发者ID:rhwy,项目名称:SampArch,代码行数:4,代码来源:PostRepository.cs

示例6: PostsRepository

 public PostsRepository(IDbContextFactory dbContextFactory)
 {
     DbContext = dbContextFactory.GetContext();
     DbSet = DbContext.Set<Post>();
 }
开发者ID:kjendrzyca,项目名称:SimpleBlog,代码行数:5,代码来源:PostsRepository.cs

示例7: UnitOfWork

 public UnitOfWork(IDbContextFactory dbContextFactory)
 {
     _dbContext = dbContextFactory.GetContext();
 }
开发者ID:sap-sh,项目名称:t,代码行数:4,代码来源:UnitOfWork.cs

示例8: CategoriesRepository

 public CategoriesRepository(IDbContextFactory dbContextFactory)
 {
     DbContext = dbContextFactory.GetContext();
     DbSet = DbContext.Set<Category>();
 }
开发者ID:kjendrzyca,项目名称:SimpleBlog,代码行数:5,代码来源:CategoriesRepository.cs

示例9: UserCredential

 public UserCredential(IDbContextFactory dbContextFactory)
 {
     var dbContext = dbContextFactory.GetContext();
     _dbAdGroupSet = dbContext.Set<ADGroup>();
 }
开发者ID:sap-sh,项目名称:t,代码行数:5,代码来源:UserCredential.cs


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