Пример #1
0
        /// <summary>
        /// 保证EF上下文对象线程内唯一.
        /// </summary>
        /// <returns></returns>
        public static DbContext CreateDbContext()
        {
            DbContext db = (DbContext)CallContext.GetData("db");

            if (db == null)
            {
                db = new YDFrameEntities();
                CallContext.SetData("db", db);
            }
            return(db);
        }
Пример #2
0
 public List <Sys_Menu> GetMenuByUserName(string userName)
 {
     using (YDFrameEntities db = new YDFrameEntities())
     {
         var query = (from a in db.Sys_User
                      where a.UserName == userName
                      join b in db.Sys_UserRole
                      on a.Id equals b.UserId
                      join c in db.Sys_RoleMenu
                      on b.RoleId equals c.RoleId
                      join d in db.Sys_Menu
                      on c.MenuId equals d.Id
                      select d
                      ).ToList();
         return(query);
     }
 }