为了避免报表中的空白,请对数据范围进行联接。
private async Task<IEnumerable<ReportDTO>> JoinDateRangeAsync( DashboardFilter filter, IQueryable<ReportDTO> queryable ) {
if (filter is null)
return null;
if (queryable is null)
return null;
var dateRange = DateHelpers.GetDatesRanges( await this.GetFromDateFromDashbordFilterAsync( filter ), GetToDateFromDashbordFilter( filter ) );
return
from d in dateRange
join r in queryable on new { x = (short)d.DayOfYear, y = (short)d.Year } equals new { x = r.DayOfYear, y = r.Year} into dr
from r in dr.DefaultIfEmpty()
select new ReportDTO( d, r );
}
我的助手功能
public static DateTime[] GetDatesRanges( DateTime from, DateTime to ) {
return Enumerable
.Range( 0, 1 + to.Subtract( from ).Days )
.Select( offset => from.AddDays( offset ) )
.ToArray();
}
以这种方式必须返回IEnumerable的问题。出于性能原因,是否可以返回IQueryable类型的对象?