You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a sample project to reproduce the issue. The unit test will see an exception System.InvalidOperationException The value of shadow key property 'MyEntity.ShadowKey' is unknown when attempting to save changes. Although the value should be known because I have a value generator in place and the debugger confirms it is used prior to the error.
Also tested for .NET Core 3.1 and .NET 5.0 -- similar error but slightly different wording.
This issue seems similar to #26330 but this isn't an owned entity situation.
publicclassShadowKeyGenerator:ValueGenerator<string?>{publicoverridestring?Next(EntityEntryentry){// This runs right before the error saying the value isn't known...return((MyDbContext)entry.Context).ShadowKeyValueOnGenerate;}publicoverrideboolGeneratesTemporaryValues=>false;}
The test:
[Fact]publicvoidRemoveFreshlyAttachedEntry(){varcontext=newMyDbContext(_options);context.ShadowKeyValueOnGenerate="value1";varentity1=newMyEntity{Key1=1};// Error here that the shadow key property isn't known although the generator has provided the value...context.Remove(entity1);context.SaveChanges();Assert.Empty(context.MyEntity.ToList());}
The text was updated successfully, but these errors were encountered:
@AndrewTriesToCode Currently value generators are only run when entities are put in the Added state--usually when Add is called. They are not run when Attach, Update, or Remove are called. Please vote (👍) for #6999 to indicate that running generators at other times is important to you.
I have a sample project to reproduce the issue. The unit test will see an exception
System.InvalidOperationException The value of shadow key property 'MyEntity.ShadowKey' is unknown when attempting to save changes.
Although the value should be known because I have a value generator in place and the debugger confirms it is used prior to the error.Also tested for .NET Core 3.1 and .NET 5.0 -- similar error but slightly different wording.
This issue seems similar to #26330 but this isn't an owned entity situation.
Thanks!
The entity:
The DbContext:
Te value generator:
The test:
The text was updated successfully, but these errors were encountered: