Skip to content

Commit

Permalink
Implemented the ability to select the reading of the latest records.
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxTes committed Apr 16, 2021
1 parent 6206146 commit a6b8634
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -239,6 +239,7 @@ private async Task GetSensorDataAsync()
{
return Context.SensorInformations
.Where(x => x.SensorGroupId == _groupSensorId[_sensorGroupSelected])
.TakeLastEx1(x => x.Id, (int)Math.Pow(10, _selectCountRecordSelected + 2))
.ToList();
});

16 changes: 16 additions & 0 deletions src/SmartThermo.Core/Extensions/DbLinqExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace SmartThermo.Core.Extensions
{
public static class DbLinqExtension
{
public static IEnumerable<TSource> TakeLastEx<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector, int N)
{
return source.OrderByDescending(selector)
.Take(N)
.OrderBy(selector);
}
}
}

0 comments on commit a6b8634

Please sign in to comment.