✅ How Do I Save a New Fully Defined Relationship in EF Core?
Ok, so if I have a token which looks like this
and I have a user
How do I create a new token if the user doesn't exist?
13 Replies
create the token and the user?
So when creating the token how do I define the user?
Why is user property in token required?
Yeah good point maybe it’s not needed
What have you tried so far? Should be as simple as adding the token instance to the user's token list and saving the context
I haven’t tried it yet I’ve been busy with work but if I add the token to the users token list how do I set the user on the token
If the user didn’t previously exist
Need to make a user first.
So when I make the user, then I just set the token list to empty?
You don't need to set it to anything, but yes
It's required
Making navigation properties required does not seem like a good idea to me
I'm not sure how modern EF Core deals with it, though
So it ended up working fine by setting the list to empty
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.