-1
如何以LINQ實現以下SQL查詢到實體查詢?如何以linq的形式實現以下SQL查詢到實體查詢?
select *, MIN(QueuedDate)
from pcm_transactions
where QueuedDate IS NOT NULL And ExecutionDate IS NULL
group by SimId
我花了幾個小時思考和嘗試varius方法 - 希望在這裏找到正確的答案。
編輯:
這是我第一次嘗試中的一種:
// Get the oldest queued action
var queuedTransactions =
(from t in db.TransactionSet
where t.QueuedDate.HasValue && !t.ExecutionDate.HasValue
group t by new { t.TransactionId, t.QueuedDate } into tr
select new
{
Transaction = db.TransactionSet.First(q => q.TransactionId == tr.Key.TransactionId),
QueuedDate = tr.Min(m => m.QueuedDate)
}).ToList();
的一個問題是,SQL是無效的開始;你必須按每個不是聚合表達式的列進行分組(例如min/max等),所以「select *」根本沒有意義。您是否有樣本數據和所需結果來幫助我們將其重寫到Linq? – Will 2010-09-07 17:32:23
好的,但我需要整行 - 不只是最小的QueuedDate - 我該如何實現? – 2010-09-08 15:12:55