to disable the entity lazy load, The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

 

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

        public static List<Menu> Get(int appid)
        {
            List<Menu> menuList = null;
            using(wechatEntities ctx=new wechatEntities())
            {
                //disable lazyload
                ctx.Configuration.LazyLoadingEnabled = false;
                var tmp = from x in ctx.Menu where x.APPId==appid select x;
                menuList = tmp.ToList();
              
            }
            return menuList;
        }
        public static List<Menu> Get(int appid)
        {
            List<Menu> menuList = null;
            using(wechatEntities ctx=new wechatEntities())
            {
                //or using include
                var tmp = from x in ctx.Menu.Include("Menu1") where x.APPId == appid select x;
                menuList = tmp.ToList();
            }
            return menuList;
        }

 

posted @ 2014-02-17 13:54  zyip  阅读(414)  评论(0编辑  收藏  举报