2009年7月2日
摘要: 使用Linq的时候常会遇到延迟加载带来的问题,比如2个表class(id,name),student(id,classId,name)当从数据层取到某个student对象后,想要取他对应的班级的名称,则会报上下文环境以被释放的错误!代码如下:数据层: public student getStudentById(int id) { using(DBDataContext dc = new DBDataContext()) { student st = dc.students.single(s=>s.id==id); return st; } } 上层使用getStudentById:stu 阅读全文
posted @ 2009-07-02 18:00 Be a Professional Programmer. 阅读(567) 评论(0) 推荐(0) 编辑