meh*_*ran 3 entity-framework aggregate
我想根据不同的条件得到一组数:
var invoices = new AccountingEntities().Transactions
var c1 = invoices.Count(i=>i.Type = 0);
var c2 = invoices.Count(i=>i.Type = 1);
var c3 = invoices.Count(i=>i.Type = 2);
Run Code Online (Sandbox Code Playgroud)
如何在一次数据库往返中调用所有三个查询以提高性能?
当然,只需将您的三个计数包装在POCO或匿名类型中:
using (var invoices = new AccountingEntities())
{
var c = (from i in invoices.Transactions
select new
{
c1 = invoices.Count(i=>i.Type = 0),
c2 = invoices.Count(i=>i.Type = 1),
c3 = invoices.Count(i=>i.Type = 2)
}).Single();
}
Run Code Online (Sandbox Code Playgroud)
另外,正如我所示,处理你的上下文.
| 归档时间: |
|
| 查看次数: |
1533 次 |
| 最近记录: |