-
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
[Bug]: The Property uses ValueGenerator
in complex FK is not tracked correctly
#26332
Comments
@mohamed-seada-1994 By default, EF Core assumes value generators generate values that can change from run to run. Starting in EF Core 6.0, this can be overridden on the value generator with public class TenantIdGenerator : ValueGenerator<Guid>
{
public override Guid Next(EntityEntry entry)
=> Guid.Parse("98D06A82-C691-4988-EA39-08D98E2C8D8F");
public override bool GeneratesTemporaryValues => false;
public override bool GeneratesStableValues => true;
} I tested with your code using the EF Core 6.0 RC2 release and it results in both test cases passing. |
@ajcvickers Thank you for your answer. For now, I need to find a solution for EF Core 5, addedEntityEntry.Property("TenantId").CurrentValue = addedEntityEntry.Property("TenantId").CurrentValue; I test this solution and it works. |
@mohamed-seada-1994 That seems reasonable. |
@ajcvickers Thanks |
Setup
ValueGenerator<Guid>
. (TenantId
)Error and notes
When adding a book with no author without setting the
TenantId
CurrentValue
forTenantId
prop when debugging theEntityEntry
However, When adding a book with no author and **setting the TenantId Manually, Succeded with no errors.
I noticed a difference when debugging
EntityEntry.InternalEntry.IsKeyUnknown
is set withtrue
in the first case andfalse
in the second case.Code Sample (Console App)
https://github.com/mohamed-seada-1994/EFCore-ValueGenerator-Bug-Sample
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 5.0
Operating system: Win10
IDE: Visual Studio 2019 16.9.6
The text was updated successfully, but these errors were encountered: