我有此查詢的SQL Server服務器做我想做的實體法.. 我怎樣才能將其轉換爲LINQ轉換SQL查詢到LINQ基於
select t1.IDHardware,h.DescricaoHardware
from dbo.ProcessoHardware t1
INNER JOIN
(select t2.IDHardware, max(t2.IDProcessoHardware) as maxVisit
from dbo.ProcessoHardware t2
group by t2.IDHardware,t2.IDProcesso) v ON
v.maxVisit = t1.IDProcessoHardware JOIN dbo.Hardware h ON t1.IDHardware=h.IDHardware
where t1.Estado=1 AND IDProcesso=1
這就是我現在......但我無法算出它過去這一點..
var ProcHardware = (from procHardware in db.ProcessoHardwares
where procHardware.IDProcesso == IDProcesso
select new { procHardware.IDHardware, procHardware.IDProcessoHardware, procHardware.IDProcesso, procHardware.Estado } into x
group x by new { x.IDHardware, x.IDProcesso, x.IDProcessoHardware, x.Estado } into t
let Max = t.Max(g => g.IDProcessoHardware)
select new { IDHardware = t.Key.IDHardware, Estado = t.Key.Estado, t.Key.IDProcesso,IDProcessoHardware=t.Key.IDProcessoHardware,cMax=Max }).ToList().Where(t => t.Estado == 1 && t.IDProcesso == IDProcesso && t.IDProcessoHardware==Max).Select(c => new VMProcessoChooseHardware
{
IDHardware = c.IDHardware
});
我有此表與表過程..這臺被稱爲processHardware涉及的表硬件。這個表由discribed:IDProcessHardware IDProcess IDHardware國家
領域狀態可以有3個狀態(1 - 插入,2-刪除,3-替代)..所以我可以我有此:
IDProcessHardware IDProcess IDHardware State
1 10 1 1
2 10 2 1
3 10 1 2
4 10 1 1
5 20 1 1
我想要得到的是插入IDHardware但未從進程中刪除的IDHardware。 所以通過給IDProcess = 10我想與硬件ID 1和2的硬件..
IDProcessHardware IDProcess IDHardware State
1 10 1 1
2 10 2 1
3 10 1 2
4 20 1 1
在表
以上通過給出IDProcess 10,它應該給我的硬件ID 2
在此先感謝...