使用 C#、NHibernate、NHibernate 到 LINQ。使用 NHibernate to LINQ,我没有 JOIN 功能。我也不能使用 QueryOver。
我有一个 LINQ 查询来计算潜在客户和销售额的数量。此表仅在新的潜在客户或销售完成时创建,因此有时不会插入任何行。执行以下查询有效
var query3 = query2.AsEnumerable()
.Where(x => x.Created <= toDate.Value && x.Created >= fromDate.Value)
.GroupBy(x => x.Created.Date)
.Select(g => new ReferrerChart {
Date = g.Key.Date,
LeadsCount = g.Count(x => !x.IsSale),
SalesCount = g.Count(x => x.IsSale)
});
但有些日期不在那里(有 0 个潜在客户和销售的日期)。
如何在不使用连接的情况下包含这些日期并让他们设置 LeadsCount = 0 和 SalesCount = 0?
编辑:
有效的最终结果:
var selectedFromDate = fromDate.Value;
var selectedToDate = toDate.Value;
var selectedDates = Enumerable.Range(0, 1 + selectedToDate.Subtract(selectedFromDate).Days)
.Select(offset => new ReferrerChart {
Date = selectedFromDate.AddDays(offset),
LeadsCount = 0,
SalesCount = 0
})
.ToList();
var query3 = Find(x => x.Source == "UserRef").AsEnumerable()
.Where(x => x.Created <= toDate.Value && x.Created >= fromDate.Value)
.GroupBy(x => x.Created.Date)
.Select(g => new ReferrerChart {
Date = g.Key.Date,
LeadsCount = g.Count(x => !x.IsSale),
SalesCount = g.Count(x => x.IsSale)
}).ToList();
var result = query3.Union(
selectedDates
.Where(e => !query3.Select(x => x.Date).Contains(e.Date)))
.OrderBy(x => x.Date);