Beispiel #1
0
        /// <summary>
        /// 保证一次请求只创建一个EF上下文
        /// </summary>
        /// <returns></returns>
        public static DbContext CreateDbContext()
        {
            DbContext dbContext = CallContext.GetData("dbContext") as DbContext;

            if (dbContext == null)
            {
                dbContext = new LotteryEntities();
                CallContext.SetData("dbContext", dbContext);
            }
            return(dbContext);
        }