即时通讯使用EF6和im在多个级别急切加载的匿名类型中有问题项目:这是一个例子:
var scheduledList = db_hms.Scheduled
.Include(s => s.scheduled_product_service.Select(sps => sps.Product_Service))
.Where(s => s.id_medical_doctor == idMedic)
.Select(sch => new
{
id_scheduled = sch.id_scheduled,
id_natural_person = sch.id_natural_person,
scheduled_product_service = sch.scheduled_product_service,
obs = sch.obs,
}).ToList();
所以scheduled_product_service是一个列表而Product_Service
是该列表上的一个对象,问题是当我执行这段代码,然后尝试获取Product_Service
时我得到一个空例外。
任何人都知道我做错了什么?
答案 0 :(得分:0)
现在有点迟了但是当我现在正在努力解决这个问题时,似乎实体框架不支持预测加载和投影。您需要将整个数据加载到内存中,然后进行投影:
var scheduledList = db_hms.Scheduled
.Include(s => s.scheduled_product_service.Select(sps => sps.Product_Service))
.Where(s => s.id_medical_doctor == idMedic)
.ToList()
.Select(sch => new
{
id_scheduled = sch.id_scheduled,
id_natural_person = sch.id_natural_person,
scheduled_product_service = sch.scheduled_product_service,
obs = sch.obs,
});
这应该对你有用,但它并不是最佳的!