-
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
IndexOutOfRange for EntityEntry.GetDatabaseValues() with complex type and TPH #32701
Labels
area-dbcontext
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Milestone
Comments
Note for triage: still repros on the latest daily. We should consider patching. @Wasserwecken Thank you so much for posted a runnable, simple repro. It makes all the difference! |
Still happens in the release of 8.0.1. Heres a better code snipped to get to the origin of the exception: using (var ctx = new CustomContext())
{
var entry = ctx.Entry(ctx.Suppliers.First());
var dbValues = entry.GetDatabaseValues()!;
// This shows that some indicies are invalid
foreach (var prop in dbValues.Properties)
Console.WriteLine(prop.GetIndex());
// This fails
entry.Reload();
// This happens kind of internally in entry.Reload()
entry.OriginalValues.SetValues(entry.GetDatabaseValues()!);
// This happens kind of internally in OriginalValues.SetValues()
// The exception occurs within the index accessor of dbValues
foreach (var prop in dbValues.Properties)
entry.OriginalValues[prop] = dbValues[prop];
} |
ajcvickers
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Jan 14, 2024
ajcvickers
added a commit
that referenced
this issue
Jan 22, 2024
ajcvickers
added a commit
that referenced
this issue
Jan 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-dbcontext
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
Servicing-approved
type-bug
Problem
I want to update the original values of an entity manually, therefore I use
GetDatabaseValues
.Unfortunately in a specific edge case the indicies for
IProperty
onArrayPropertyValues
are partially invalid.This results in an IndexOutOfRangeException because TPH properties indicies do not fit the underlying value array.
The root of the problem might be that
Not only does this result in an exception, this also:
EntityEntry.Reload()
because it does the same internally.This problems only occures on TPH properties, there is no exception with normal entities.
Details
The value set loaded contains all proeprties except the complex type ones.
But the index of the additional property of the
Supplier
-Type does returns4
withdbValues.Properties.ToArray()[3].GetIndex()
which results in an IndexOutOfRangeException
Example
The following code should reproduce the exception on the line
entry.OriginalValues.SetValues(dbValues);
.Im using .NET 8.0 with EFCore 8.0.0 and VS Studio 17.8.3.
Before running the code, migrations have to be added (
Add-Migration Init
)The text was updated successfully, but these errors were encountered: