What is the equivalent in LINQ
of SqlFunctions.DateDiff
so that the code below can be ported?
public class OHLC
{
public string Symbol { get; set; }
public System.DateTime Date { get; set; }
public double Open { get; set; }
public double High { get; set; }
public double Low { get; set; }
public double Close { get; set; }
public long Volume { get; set; }
}
public enum DateGroupType
{
Day,
Week,
Month,
Quarter,
Year
}
private IEnumerable<IGrouping<int?, OHLC>>
GroupByDate(IEnumerable<OHLC> data, DateGroupType group, DateTime startDate)
{
switch (group)
{
case DateGroupType.Day:
return data.GroupBy(x => SqlFunctions.DateDiff("dd", startDate, x.Date));
case DateGroupType.Week:
return data.GroupBy(x => SqlFunctions.DateDiff("ww", startDate, x.Date));
case DateGroupType.Month:
return data.GroupBy(x => SqlFunctions.DateDiff("mm", startDate, x.Date));
case DateGroupType.Quarter:
return data.GroupBy(x => SqlFunctions.DateDiff("qq", startDate, x.Date));
case DateGroupType.Year:
return data.GroupBy(x => SqlFunctions.DateDiff("yy", startDate, x.Date));
default:
throw new NotSupportedException($"Grouping by '{group}' is not supported");
}
})