わかりました、このようなもの。確かめるには少し情報が必要ですが、
少しキューに入れられていますか?これは、SQL にはない linq に違いをもたらします。私はあなたのコンテキスト名も知りませんが、アイデアを得る必要があります。
var query = Context.ExportQueues.Select(x => new {
QueueItem = x.QueueItem,
Sent = !x.Queued ? 1 : 0,
Queued = x.Queued ? 1 : 0,
Exported = x.Success ? 1 : 0,
Failed = !x.Success ? 1 : 0 })
.GroupBy(x => x.QueueItem)
.Select(g => new {
QueueItem = g.Key,
Sent = g.Sum(x => x.Sent),
Queued = g.Sum(x => x.Queued),
Exported = g.Sum(x => x.Exported),
Failed = g.Sum(x => x.Failed)
}).ToList();
編集クエリでオンザフライでケースを実行することにより、これらを組み合わせることもできます。エラーがある場合、より複雑な集計はデバッグが少し難しい場合があるため、私は常に最初に上記のように書き出す傾向があります。
var query = Context.ExportQueues
.GroupBy(x => x.QueueItem)
.Select(g => new {
QueueItem = g.Key,
Sent = g.Sum(x => !x.Queued ? 1 : 0),
Queued = g.Sum(x => x.Queued ? 1 : 0),
Exported = g.Sum(x => x.Success ? 1 : 0),
Failed = g.Sum(x => !x.Success ? 1 : 0 )
}).ToList();