3

Include ステートメントを使用すると爆発する次の Linq2Entities クエリがあります。Include() を削除すると、クエリは正常に実行されます。

私が得る例外は次のとおりです。

「メソッド 'System.Data.Entity.Infrastructure.DbQuery 1[Pedicab.DB.Equipment] Include(System.String)' declared on type 'System.Data.Entity.Infrastructure.DbQuery1[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; } }
}

何か案は??

ありがとう!ジョン

4

0 に答える 0