dhl:Using:方法调用完毕立即释放。

方法1:

private TaoXueDBEntities _TaoXueDBEntities = new TaoXueDBEntities();

//销毁TaokeRepository的时候才能销毁_TaoXueDBEntities 建议采用using方法。

public IList<Lesson> GetAllLesson()

{

 var query = _TaoXueDBEntities.ExecuteStoreQuery<Lesson>("SELECT * FROM  dbo.Lesson");
                return query.ToList();

}

--

Using:方法调用完毕立即释放。
        public IList<Lesson> GetAllLesson()
        {
            using (var _TaoXueDBEntities = new TaoXueDBEntities())
            {
                var query = _TaoXueDBEntities.ExecuteStoreQuery<Lesson>("SELECT * FROM  dbo.Lesson");
                return query.ToList();
            }
        }

posted @ 2010-09-21 17:47  肚肚  阅读(188)  评论(0编辑  收藏  举报