Update Multiple Entities in One Query EF Core
I'm looking for a way to update multiple entities, something that represents
I've googled around and answers seems to execute a select-where query first then update each entity using a loop, then update them one by one.
Is there a way for this? Thanks in advance
10 Replies
Select all, loop over them, modify them, save changes
Unless you update to EF Core 7, then you can execute bulk updates without fetching
ooh 🤔
so there's no actual way in EF Core 6 to do this without fetching?
You can do some shenanigans with creating objects with new state and existing IDs, setting them to modified in the change tracker, and saving that
But it's janky, and you still need the IDs
in this case, probably meant to be in different question,
But i encountered this when I wanted to change an entity's field which is part of the key, but it says
Is there a way to just do it anyway?
If it's a key, that means it can be used as a foreign key somewhere else. IIRC EF doesn't support manually editing keys
okay
anyway, good to know this
Unless you update to EF Core 7thanks a lot 😄
Entity Framework Plus
Learn Entity Framework Plus using EntityFramework Plus by documentation & example
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Yep
Plan for Entity Framework Core 7.0
The themes and features planned for EF Core 7.0