嗨,我有一个使用Entity Framework 6和角度一起进行延迟加载的问题。
当我从角度服务调用我的服务器api时,我经常得到一个响应,其中延迟加载的客户,员工和服务对象返回null。
appointmentService.getTodaysAppointments().success(function(data) {
vm.appointments = data.appointments;
});
以下是我的json响应的样子:
[
{
"customer": null,
"employee": null,
"service": null,
"startDate": "2014-09-10T15:00:00",
"endDate": "2014-09-10T16:00:00",
"typeOfAppointment": 1,
"isDeleted": false,
"creationTime": "1900-01-01T00:00:00",
"creatorUserId": 10,
"id": 3494
}
]
这是因为Entity Framework在将对象发送到客户端之前尚未处理该对象。
有没有办法解决这个问题而不删除延迟加载?
答案 0 :(得分:2)
为什么不使用Include
linq扩展来加载getTodaysAppointments
服务器实现中所需的数据
dbContext.Appointments.Single(wherecondition)
.Include(a=>a.customer)
.Include(a=>a.employee)
.Include(a=>a.service)
.ToList()
答案 1 :(得分:0)
我的建议是不要对这样的查询使用延迟加载。这对性能有害,因为您正在对DB进行多次查询而不是一次。如果要从相关表返回数据,请始终使用Include。
context.Appointments.Include("Customer").Include("Employee")