❔ ✅ 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?![](https://utfs.io/f/b9e444d6-fa00-4910-9563-03cc5fe5ffd8-1nq2cb.png)
9 Replies
![](https://utfs.io/f/cd1749a7-b9df-40f2-97bc-2ef7d303b75e-1nq2cb.png)
![](https://utfs.io/f/abc52df6-d85e-4a20-a467-463ab4709058-1nq2cb.png)
![](https://utfs.io/f/afa59391-0c19-40e2-885a-762754166bb6-1nq2cb.png)
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...
![](https://utfs.io/f/0d416baf-a4b2-4971-81cd-95d4c83e4c61-1nq2cb.png)
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.