Entity Framework 4.0 自跟踪加载导航属性
我的数据访问类有这段代码,我想在其中加载所有患者应有的位置,Patient.Addresses、Patient.Examinations、Examinations.LeftEye、Examinations.RightEye ....
如何加载所有相关数据一个病人?我连地址都没有加载。
这是当前的代码:
db.Patients.Include("Addresses");
db.Patients.Include("Examinations");
db.Examinations.Include("LeftEyePictures");
db.Examinations.Include("RightEyePictures");
List<Patient> list = db.Patients.ToList();
list.ForEach(p => p.ChangeTracker.ChangeTrackingEnabled = true);
return list;
谢谢。
I have this code for my Data Access class where I want to load all the Patients where they some should have, Patient.Addresses, Patient.Examinations, Examinations.LeftEye, Examinations.RightEye....
How to Load all the related data with a patient? I havent managed to load even the address.
This is the current code:
db.Patients.Include("Addresses");
db.Patients.Include("Examinations");
db.Examinations.Include("LeftEyePictures");
db.Examinations.Include("RightEyePictures");
List<Patient> list = db.Patients.ToList();
list.ForEach(p => p.ChangeTracker.ChangeTrackingEnabled = true);
return list;
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法:
第一:
加载前启用延迟加载
然后禁用,如果您不需要它
第二:手动加载
您可以在加载前检查:(此或类似)
there is two ways:
1st:
enable lazzy loading before loading
Then disable, if you dont need it
2nd:Handload
you can chesk before loading: (this or similar)
Include
必须是查询的一部分!Include
must be part of the query!