❔ ✅ EFCore: How to add entity with one-to-many relationship without navigation property in 1 query
In my
ApplicationUser
class I have Characters
property (see screenshots), but Character
does not have a back navigation property. I want to add Character
into a database and attach it to a user with specified Id in one query. Any tips with LINQ?
9 Replies



Current solution does 2 queries 😦
You can include the fk id as a property on charactersnapshot, the just added the charactersnapshot to it's own dbset after setting the fk value
I think you can also set the shadow property value of the fk if you don't have the fk property in your entity
Shadow properties seem like a way to go, thanks
That is what I don't want to do since CharacterSnapshot is a class from my own yet external library that has nothing to do with this code
That makes no sense since theyre already mixed together...

My Web proj depends on DnD proj, to add back property in
CharacterSnapshot
I would need circular referenceNo, you only need to add a property for the id, e.g a guid or long, etc
But if you've got entity classes in different projects that's weird already
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.