✅ EFCore Nullability and Circular References
I have 2 tables which have FK's to each other due to the relationship.
I'm trying to add some seed data for a profile that needs to be created on initialisation.
I've tried two ways...
Prefixed tables with EF just to make it a little clearer.
SEED: (2nd example - circular reference)
MODEL: (1st example - missing FK in EFAlias)
I'm trying to add some seed data for a profile that needs to be created on initialisation.
I've tried two ways...
- I'm getting an SQL 19 error which is a expected field that isn't provided (NULL). If I set the FK in EFAlias to Nullable with
?, then the field in the database isn't populated (which makes sense). However, with the above scenario if I ever lookup the seeded user from their EFAlias, FK to EFUser isn't populated. So it's not possible. - If I remove the Nullable statement in the property and provide the UserId and AliasId in the seed data, the migration fails due to Circular Reference (which again, makes sense)
Prefixed tables with EF just to make it a little clearer.
SEED: (2nd example - circular reference)
MODEL: (1st example - missing FK in EFAlias)