下午好,
我在延迟加载空子对象时遇到问题。考虑以下代码:
// Retrieve all repairs
var repairs = this.db.Repairs.Include("Brand").Include("Model");
// JUST FOR TESTING PURPOSES
// Some repairs do not have a brand or model. This query returns about 14 results
var reps = this.db.Repairs.Where(r => r.ModelId == 0 || r.BrandId == 0);
// Map the repairs to the viewmodel
var ret = repairs.Select(qRepair => new RepairListViewModel
{
Brand = qRepair.Brand == null ? "Unkown" : qRepair.Brand.Name,
CompanyName = qRepair.User.CompanyName,
CustomerName = qRepair.CustomerName,
Created = qRepair.Created,
DamageNumber = qRepair.DamageNumber,
Id = qRepair.Id,
Model = qRepair.Model == null ? "Unkown" : qRepair.Model.Name,
OrderNumber = qRepair.Order.OrderNumber,
Printed = qRepair.Printed,
Status = qRepair.Status
});
在此之后,返回列表以供在 Kendo UI Grid 中使用。
但是,品牌或型号名称为“Unkown”的产品没有维修。它似乎跳过了品牌或型号为空的维修。我在这里想念什么?!
提前致谢!