-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Query of the history of a temporary table returns additional records #27035
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
You are querying Invoices... |
Hi @ErikEJ , Based on official documentation, If this is not the correct way to consult the historical table, could you please guide me as to what should be the right way. Thank you very much! :) |
Sorry, I thought you had a InvoicesHistory entity |
I understand, don't worry. When you have a little time, you can take a look please. I am convinced that many of us would appreciate it! :) |
TemporalAll maps to |
Note that the What's new documentation was recently updated to reflect this. |
@ajcvickers, do you refer this ? Now say that current or history data... |
@mendozagit As it says in the linked doc, "Notice that the ValidTo column (by default called PeriodEnd) contains the datetime2 max value. This is always the case for the current rows in the table." |
Staff, thanks for the clarifications. Personally, I think the temporary tables are a wonderful feature of EFC 6, however, in my opinion it is confusing how to query. I think it will be a great tool, but it can be improved further. For example, Example for item 3 Something like that.. , so in this where idToAudit be 1 or 2 or 3 or 4 or 5. query, should not recover records, because there was no update or deletion.
Example. If I insert 5 records in the invoice table (only insert, no update) SSMS: Select * from InvoiceHistory returns 0 records. This in my opinion is confusing. In my opinion, based on readings, forums, videos this would help developers a lot. |
This is tracked by #26463.
The EF Core implementation aligns with the way this is implement in SQL Server. See https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-tables?view=sql-server-ver15. The way the columns and queries are handled matches how temporal tables are implemented by SQL Server. I don't think it makes sense for EF to do something different here; that would both be confusing, and would create mapping issues when attempting to go from EF to SQL Server. |
File a bug
Imagine that you have a simple invoices and InvoicesHistory entities, also imagine that you have already inserted some records (only inserted, not updated ).
So if you query from SQL Server Management Studio (SSMS), the [InvoicesHistory] table has no records. (Of course, because there were no updates)
The surprise is that if you query from EFC , as many records as the temporary table has are retrieved.
i.e
Query from SSMS
Invoices has 5 insertions,
InvoicesHistory has 0 insertions (because Invoices were no updates)
The surprise is that if you query the InvoicesHistory table from EFC, it returns 5 records. (for this example)
stack traces
Include provider and version information
EF Core version: EFC 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system:
Edición Windows 10 Pro
Versión 21H2
Se instaló el 08/12/2021
Compilación del SO 19044.1387
Experiencia Windows Feature Experience Pack 120.2212.3920.0
IDE: Microsoft Visual Studio Professional 2022 (64-bit)
Version 17.0.3
The text was updated successfully, but these errors were encountered: