-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set CollectionEntry.IsModified to true
when removing items from a collection
#24076
Comments
@joaodvargas In retrospect, I wish we had not implemented |
@ajcvickers thanks for the reply. I'd say this is also a problem of consistency, not just ambiguity - and it affects both
I've added tests for adding entities via those 4 different options and they all pass, furthering the inconsistency. Full test suite and setup can be seen here. My actual use case for this is to from a top level entity (my aggregate root) be able to identify, on |
Would just like to add that i've just come across this very issue myself (and find it interesting that this issue is fresh hahah). As a note if you are able to figure out a stopgap for the meantime before something is implemented it would be great if you could share. |
I'm afraid I only got as far as I mentioned in my previous comment - I can use the internal snapshots to figure out when a reference navigation is deleted (the current entity has the property clear but the snapshot still points to the previous entity, which is now marked I'm currently considering having to track these sort of changes in my BL/Domain and manually mark the aggregate entity as changed there, forcing a version bump that way. Not as bullet proof as something the |
that's exactly what i started doing yesterday. not exactly the best solution but hey it works for now |
I am in the same situation as described by @joaodvargas . A solution for such a scenario without having to contaminate the domain would be great. |
Same problem here. I'm trying to implement mixed concurrency mode - if there's a conflict (DbUpdateConcurrencyException) I apply changes only for properties that have IsModified = true (updated in logic). It doesn't work when item was removed from collection. Moreover there's something wrong with Reload() method on entity because it doesn't reload collection items from database (I'm using Cosmos db provider) |
I've just cam across this after wondering why our BL was failing when looking at IsModified in certain scenarios (i.e. removing entries), Would love it if this got some traction, guess I'm stuck with implementing myself for the time being |
true
when removing items from a collectiontrue
when removing items from a collection
I have the same issue too. Would be great to see a fix for this. |
Gald it wasn't only me finding CollectionEntry.IsModified not acting as logic dictates |
I also noticed this behaviour. It currently really a pain for me to bypass this issue. Is it possible to load the original database values for the collection and do a manual compare? |
This comment was marked as resolved.
This comment was marked as resolved.
Everyone, please refrain from posting comments that say "me too" or "please give this more priority"; this issue currently has only 13 votes in total, meaning that it's affecting very few users, and therefore comes up pretty low in the list of issues. That doesn't mean it necesarily won't get done, but for now please just upvote it rather than posting comments. |
File a bug
The
IsModified
property on aCollectionEntry
does not correctly reflect it has been modified if the action is only to remove an entry from the collection.The intent seems to be for that field to reflect that, given in the source code there are code checks for entries with a
State
ofDeleted
and previous work done for #10450.Include your code
This is easy to reproduce adding some additional cases to your
SqlServerEndToEndTests
fixture, which I've tested in my own efcore fork:weapon
entity after setting it asplayer.CurrentWeapon = weapon;
would throw an exception as it seems EF tries to clear both foreign keys forCurrentWeapon
inPlayerCharacter
-CurrentWeaponId
andGameId
- however becauseGameId
is used in other required relationships that causes an exception to be thrown. Clearing the weaponplayer.CurrentWeapon = null;
as opposed to deleting the entitycontext.Remove(weapon);
seems to work fine, so perhaps that's a possible bug as well?Include stack traces
n/a
Include verbose output
n/a
Include provider and version information
Using latest released EF Core version (3.1.1) targeting .NET 5.0
The text was updated successfully, but these errors were encountered: