FK properties with default values aren't always marked as store-generated #23974
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Originally filed by @ruirodrigues1971 at PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#1304
Smaller repro from @lauxjpn:
This one is a very weird issue. I reproduced the behavior not just with MySQL, but also with SQL Server. It seems that this issue is part of EF Core.
The sample code I used for reproduction:
Program.cs
Console output (SQL)
As you can see, the table declarations in SQL are fine.
However, the last
INSERT
statement is unexpected:Because
IdUserState
has been configured with theHasDefaultValue(1)
and we have not explicitly set a value in ourcontext.Users.Add(new User())
statement, it should not be part of theINSERT
query.It gets weirder:
If I rename the
IdUserState
property toUserStateId
, the same DDL statements (with the changed column name of course) get generated as before, including the expected PKs etc., but the generatedINSERT
statement suddenly correctly omits theUserStateId
column and so theINSERT
query works as expected.If I don't rename
IdUserState
, I can still get theINSERT
statement to work, if I move the property configuration below the relationship configuration:The text was updated successfully, but these errors were encountered: