我有以下 Linq2Entities 查询,当我使用 Include 语句时它会爆炸 - 当我删除 Include() 时,查询执行得很好。
我得到的例外是:
“方法 'System.Data.Entity.Infrastructure.DbQuery
1[Pedicab.DB.Equipment] Include(System.String)' declared on type 'System.Data.Entity.Infrastructure.DbQuery
1[Pedicab.DB.Equipment]' 不能使用 'System.Data.Objects.ObjectQuery`1[Pedicab.DB.Equipment]' 类型的实例调用”
方法:
public List<ShiftSummary> GetDriversOutOnShift()
{
return (from s in _context.Shifts
join l in _context.Leases on s.LeaseId equals l.Id
join lt in _context.LeaseTypes on l.LeaseTypeId equals lt.Id
join d in _context.Drivers on l.DriverId equals d.Id
let eqs =
from se in _context.ShiftEquipments
join eq in _context.Equipments.Include("EquipmentType") on se.EquipmentId equals eq.Id
where se.ShiftId == s.Id
select eq
where s.EndDate == null
orderby s.StartDate descending
select new ShiftSummary
{
FirstName = d.FirstName,
LastName = d.LastName,
LeaseType = lt.LeaseDescription,
LeaseAmount = s.LeaseRateAmount,
LeasePercent = s.LeaseRatePercent,
StartDate = s.StartDate,
DriverId = d.Id,
ShiftId = s.Id,
Equipment = eqs
})
.ToList();
}
班次总结类:
public partial class ShiftSummary
{
public int ShiftId { get; set; }
public int DriverId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string LeaseType { get; set; }
public decimal? LeaseAmount { get; set; }
public int? LeasePercent { get; set; }
public string TotalTimeOut { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public decimal TotalEarned { get; set; }
public decimal? TotalCredits { get; set; }
public decimal? TotalFees { get; set; }
public decimal TotalDepositExpected { get; set; }
public decimal TotalDeposited { get; set; }
public bool FlaggedForReview { get; set; }
public bool DepositConfirmed { get; set; }
public IEnumerable<Equipment> Equipment { get; set; }
public string Driver { get { return FirstName + " " + LastName; } }
}
有任何想法吗??
谢谢!乔恩