Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't update row when UseHistoryTable is enabled. #33397

Closed
warkakw opened this issue Mar 25, 2024 · 4 comments
Closed

Can't update row when UseHistoryTable is enabled. #33397

warkakw opened this issue Mar 25, 2024 · 4 comments

Comments

@warkakw
Copy link

warkakw commented Mar 25, 2024

Hi

Microsoft.EntityFrameworkCore: 8.0.3
Microsoft.EntityFrameworkCore.SqlServer: 8.0.3

I use EF Core Power Tools with Reverse Engineer.

My MS SQL db table has system versioning on. Data table and historical table have equals columns.

Autogenereted context has this:

   .ToTable(tb => tb.IsTemporal(ttb =>
        {
            ttb.UseHistoryTable("Project", "history");
            ttb
                .HasPeriodStart("SysStartTime")
                .HasColumnName("SysStartTime");
            ttb
                .HasPeriodEnd("SysEndTime")
                .HasColumnName("SysEndTime");
        }));

When I try update row i see error:

"Unable to cast object of type 'System.Int32' to type 'System.DateTime'." in

at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.d__4.MoveNext()
at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.d__2.MoveNext()
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.d__50.MoveNext()
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.d__50.MoveNext()
at Microsoft.EntityFrameworkCore.SqlServer.Update.Internal.SqlServerModificationCommandBatch.d__15.MoveNext()
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.d__9.MoveNext()
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.d__9.MoveNext()
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.d__9.MoveNext()
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.d__111.MoveNext()
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.d__115.MoveNext()
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.d__7`2.MoveNext()
at Microsoft.EntityFrameworkCore.DbContext.d__63.MoveNext()
at Microsoft.EntityFrameworkCore.DbContext.d__63.MoveNext()

If I remove code in context file (shown above) update works.

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 26, 2024

Are you generating from a .dacpac?

@warkakw
Copy link
Author

warkakw commented Mar 26, 2024

No, like this:
image
image
image
image
image

What is interesting, other tables with history works properly.
UPDATE: Error also applies to other tables.

@maumar
Copy link
Contributor

maumar commented Apr 11, 2024

can you try latest EF 9 preview? We have done a large refactoring to how migrations deal with temporal tables, which fixes a lot of bugs in the area - #32239

@ajcvickers
Copy link
Contributor

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants