The equivalent of this Linq to SQL. RRS feed

  • Question

  • Hey, sorry if i'm in the wrong Forum.

    I have this code
    var TickInterval = new TimeSpan(0, 1, 0, 0).Ticks;
    var hour = from ohlc in list
               // Calculate the chronological, natural-time, intra-day index 
               // of the bar associated with a tick.
               let Index = ohlc.Time.TimeOfDay.Ticks / TickInterval
               // Calculate the begin-time of the bar associated with a tick.
               // For example, turn 2011/04/28 14:23.45 
               // into 2011/04/28 14:20.00, assuming 5 min bars.
               let Start = ohlc.Time.Date.AddTicks(Index * TickInterval)
               // Produce raw tick-data for each bar by grouping.
               group ohlc by Start into DataSeries
               select new Ohlc
                   Id = index++,
                   Time = DataSeries.Key,
                   Open = DataSeries.First().Bid,
                   High = DataSeries.Select(p => p.Bid).Max(),
                   Low = DataSeries.Select(p => p.Bid).Min(),
                   Close = DataSeries.Last().Bid,
                   Volume = DataSeries.Sum(p => p.Volume)
    The problem is that when i get the query, i get it in IEnumerable, so when the Linq starts, all the IEnumerable has to be casted to Array or List. And that takes a lot of time.

    So my question is, what is the equivalent of that Linq in SQL? Maybe bypassing the Linq and just making the SQL query more complex the time will be reduced.

    Thank you.
    • Edited by Fernando J Friday, March 6, 2020 5:52 AM
    Friday, March 6, 2020 5:52 AM