public static void Main(string[] args)
        {
            string connectionString = ConfigurationHelper.Configuration["ConnectionStrings.DefaultNullBug"];

            bool workingException = false; bool brokenException = false;

            using ( WorkingDbContext wctx = new WorkingDbContext( new DbContextOptionsBuilder<WorkingDbContext>().UseSqlServer( connectionString ).Options ) )
            {
                try
                {
                    wctx.Database.EnsureCreated();
                }
                catch ( Exception e )
                {
                    Console.WriteLine( "Failed to create working context:" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace );
                    workingException = true;
                }
                finally
                {
                    if ( !workingException )
                    {
                        Console.WriteLine( "Working context created successfully" );
                    }
                    wctx.Database.EnsureDeleted();
                }
            }

            Console.WriteLine(); Console.WriteLine(); Console.WriteLine();

            using ( BrokenDbContext bctx = new BrokenDbContext( new DbContextOptionsBuilder<BrokenDbContext>().UseSqlServer( connectionString ).Options ) )
            {
                try
                {
                    bctx.Database.EnsureCreated();
                }
                catch ( Exception e )
                {
                    Console.WriteLine( "Failed to create broken context:" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace );
                    brokenException = true;
                }
                finally
                {
                    if ( !brokenException )
                    {
                        Console.WriteLine( "Broken context created successfully" );
                    }
                    bctx.Database.EnsureDeleted();
                }
            }
            Console.ReadLine();
        }
Example #2
0
 public RoleRepository(WorkingDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #3
0
 public HomeController(WorkingDbContext db)
 {
     var list = db.Roles.ToList();
 }
Example #4
0
 public UserRepository(WorkingDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #5
0
 /// <summary>
 /// 权限仓储类构造
 /// </summary>
 /// <param name="dbContext">startup注入的数据库对象</param>
 public WorkItemRepository(WorkingDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public DepartmentRepository(WorkingDbContext dbContext)
 {
     _dbContext = dbContext;
 }