当我使用Include语句时,我有以下Linq2Entities查询 - 当我删除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();
}
Shift Summary类:
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; } }
}
任何想法?
谢谢! 乔恩