-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
EfCore 5 Update method throws "Unable to cast object of type 'System.Int32' to type 'System.Int64'." #24221
Comments
/cc @smitpatel |
The stacktrace includes update pipeline and value comparer. |
Key values between different keys are being compared in the update pipeline. I'm surprised this wasn't reported previously. |
Goddamn. Ive spent a whole day or so trying to tackle this issue in my own project, attached the debugger during migration generation and turned off Just My Code, dug right into the core of the issue, finally understood what was happening and created an SSCCE that minimally reproduced this issue. Then just as I was typing up the bug report I realised that I was targeting EF Core 5.0.4 instead of 5.0.5. I didn't think it would make any difference but bumped my SSCCE up to the latest version and tried reproducing it again...and there was no bug. I can't believe that this entire time I could have avoided all that work if I'd just noticed I was one tiny patch version behind. |
After upgrading from EFcore 3.1 to EFcore 5.0.3, some manipulations of Entities started to throw "Unable to cast object of type 'System.Int32' to type 'System.Int64'.".
Code Example
On the following Code, the line of "SaveChangesAsync()" throw "Unable to cast object of type 'System.Int32' to type 'System.Int64'.", but works fine in EFcore 3.1 full example :
Note that only values/rows were Deleted.
Stacktrace
Sorry for the Sample, I did my best converting my real project to an understandable Code.
Provider and version information
EF Core version: 5.0.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Sqlite
Target framework: NET 5.0
Operating system: Windows 10 Pro
IDE: Visual Studio 2019 16.8.4
The text was updated successfully, but these errors were encountered: