CTE involving temporal table does not translate the temporal table SQL keywords
See original GitHub issuethis…
var cte = (
from change in changeSet.TemporalAll()
where change.Id == key
select new
{
Change = change.Id,
RowNumber = Sql.Ext.RowNumber()
.Over()
.PartitionBy(change.Id)
.OrderByDesc(EF.Property<DateTime>(change, "PeriodStart"))
.ToValue()
})
.AsCte("History")
.Where(anon=>anon.RowNumber <=2)
.ToLinqToDB();
…translates to this…
WITH [History] ([RowNumber], [Id])
AS
(
SELECT
ROW_NUMBER() OVER(PARTITION BY [change_1].[Id] ORDER BY [change_1].[PeriodStart] DESC),
[change_1].[Id]
FROM
[Ephron.Metadata.DotNet].[Class] [change_1]
WHERE
[change_1].[Id] = @key_1
)
SELECT
[anon].[Id],
[anon].[RowNumber]
FROM
[History] [anon]
WHERE
[anon].[RowNumber] <= 2
… which is correct except for it is missing the temporal table keywords in the CTE…
FOR SYSTEM_TIME ALL
… it should be something like…
WITH [History] ([RowNumber], [Id])
AS
(
SELECT
ROW_NUMBER() OVER(PARTITION BY [change_1].[Id] ORDER BY [change_1].[PeriodStart] DESC),
[change_1].[Id]
FROM
[Ephron.Metadata.DotNet].[Class] FOR SYSTEM_TIME ALL as [change_1]
WHERE
[change_1].[Id] = @key_1
)
SELECT
[anon].[Id],
[anon].[RowNumber]
FROM
[History] [anon]
WHERE
[anon].[RowNumber] <= 2
I’ll attempt to implement a fix in linq2db and see if the PR will be accepted.
Issue Analytics
- State:
- Created 9 months ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Temporal Table Usage Scenarios - SQL Server
Temporal Tables are useful in scenarios that require tracking history of data changes. We recommend you to consider Temporal Tables in the ...
Read more >How to query data in a System-Versioned Temporal Tables ...
This article will cover the querying of temporal tables in SQL Server by using the FOR SYSTEM_TIME clause and its four sub clauses....
Read more >Temporal table considerations and limitations - SQL Server
A temporal table must have a primary key defined in order to correlate records between the current table and the history table, and...
Read more >C# SqlConnection Querying Temporal tables
I have a temporal table Employee with EmployeeHistory as its history table. In C#, I am using SqlConnection to query the data from...
Read more >Temporal tables -- reasons not to use them?
In the project I'm working on we're about to implement 4 temporal tables in Azure SQL. In the past I've worked with version...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Already released.
Will check what we can do here. Actually it needs support from
linq2db
side.