1
select DL.lat,
DL.lng,
DL.speed,
DL.trackedOn,
IL.speedLimit,
IL.deviceName,
IL.deviceId,
isnull(DeviceIcon, 'Content/images/beach-car.png') as DeviceIcon
from tb_DeviceLog DL
inner join (select inventoryLogId, max(trackedOn) as MaxDate
from tb_DeviceLog
group by inventoryLogId) IDL
on DL.inventoryLogId = IDL.inventoryLogId and Dl.trackedOn = IDL.MaxDate
inner join tb_InventoryLog IL
on DL.inventorylogid = IL.id
inner join tb_Logins LGN
on LGN.customers_id = IL.assignedToCustId
where LGN.userName='cadmin'
我需要一個lambda表達式用於上述查詢。在LINQ表達式中嵌套查詢加入
到目前爲止,我曾嘗試:
var query = db.tb_DeviceLog.Join(db.tb_DeviceLog, DL=>DL.inventoryLogId, DL1=>DL1.inventoryLogId, (DL,DL1)=> new{ DL1.inventoryLogId, DL1.trackedOn.Value}).GroupBy(a=>a.inventoryLogId)
但是,這是我想要的結果的一半。
VAR的查詢= db.tb_DeviceLog.Join(db.tb_DeviceLog,DL => DL.inventoryLogId,DL1 => DL1.inventoryLogId,(DL,DL1)=>新DL1.inventoryLogId,DL1.trackedOn.Value})。GroupBy(a => a.inventoryLogId) 但是,這是我想要的結果的一半。此外,我無法使用此表達式獲取TrackedOn(日期字段)的最大值。 –