-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