Repository navigation
feat: translate first() and last() aggregates from LINQ - #73
Merged
sebastian-ederer merged 2 commits intoNov 4, 2026
Merged
Conversation
Adds EF.Functions.First and EF.Functions.Last so the TimescaleDB first(value, time) and last(value, time) aggregates can be used in GroupBy queries, alone or together with TimeBucket, without raw SQL.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Adds a translator test for a generic method of TimescaleDbFunctionsExtensions that is neither First nor Last, and tests that calling EF.Functions.First and EF.Functions.Last outside a query throws. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
sebastian-ederer
self-requested a review
November 4, 2026 18:29
Member
|
@grzonu Thanks for this PR! I had this feature on my bucket list and I can mark this as done now :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
EF.Functions.First(...)andEF.Functions.Last(...), which translate to the TimescaleDBfirst(value, time)andlast(value, time)aggregates inside aGroupBy, alone or together withTimeBucket. The value and the ordering column are passed as aValueTuple.Create(value, time)pair, the same idiom Npgsql uses forCorrelation, so no custom expression type or SQL generator is needed: the translator is anIAggregateMethodCallTranslatorregistered next to the existingTimeBucketplugin (both inUseTimescaleDb()andAddEntityFrameworkTimescaleDb()). AWhereon the group becomesFILTER (WHERE ...);Distinct()andOrderBy()inside the grouping are refused with anInvalidOperationExceptionof their own, because the time argument already orders the rows (returningnullinstead let EF fail with an internalNullReferenceExceptionon keyed entities). Docs are indocs/query-functions/first-last.md.Related Issues
None.
Type of Change
Test Plan
TimescaleDbFirstLastTranslatorTestsFirstLastIntegrationTests(8 tests), plus SQL-baselineFirstLastQueryTestson the Community and Apache fixturesdotnet test):Eftdb.Tests2723 passed, 0 failed;Eftdb.FunctionalTests95 passed, 0 failedChecklist