diff --git a/DD.Persistence.Repository/Repositories/SetpointRepository.cs b/DD.Persistence.Repository/Repositories/SetpointRepository.cs index f7a719a..57cb564 100644 --- a/DD.Persistence.Repository/Repositories/SetpointRepository.cs +++ b/DD.Persistence.Repository/Repositories/SetpointRepository.cs @@ -16,14 +16,19 @@ namespace DD.Persistence.Repository.Repositories protected virtual IQueryable GetQueryReadOnly() => db.Set(); - public async Task> GetCurrent(IEnumerable setpointKeys, CancellationToken token) + public async Task> GetCurrent( + IEnumerable setpointKeys, + CancellationToken token) { var query = GetQueryReadOnly(); + var entities = await query .Where(e => setpointKeys.Contains(e.Key)) + .GroupBy(e => e.Key) + .Select(g => g.OrderByDescending(x => x.Created).FirstOrDefault()) .ToArrayAsync(token); - var dtos = entities.Select(e => e.Adapt()); + var dtos = entities.Select(e => e.Adapt()); return dtos; }