trackerdog icon indicating copy to clipboard operation
trackerdog copied to clipboard

Top-level property for any changes

Open krispharper opened this issue 7 years ago • 3 comments

Apologies for opening another issue so soon. Is there a property at the change tracker level that will indicate if any changes have been made on any of the objects in the object graph? I'm hoping to use this for a "needs to be saved" indication for backing a UI.

I saw this issue, which I think would accomplish what I need, but it involves configuring a separate event on each tracked object, which is a little cumbersome.

I didn't see anything in the documentation, but maybe I'm missing something. Right now I'm basically doing something like this

entities.SelectMany(e => e.GetChangeTracker().ChangedProperties).Any();

which could be slow if there are a lot of entities or a lot of changes.

krispharper avatar Sep 20 '18 11:09 krispharper

Hey! No problem, you may ask as many questions as you need when you find issues or you've doubts!

May you explain further details about your object graph? Is the object graph a collection? Is a change tracked collection?

If I'm not mistaken, you're looking for sharing the same object change tracker across all those entities which could drive to this other issue: https://github.com/mfidemraizer/trackerdog/issues/41

Please answer the question so I can figure out what's going on with more precision.

Thank you in advance!

mfidemraizer avatar Sep 20 '18 12:09 mfidemraizer

I am effectively looking for something similar to the HasChanges method from Entity Framework's change tracker. This gives a single place to check for any changes across all objects being tracked.

This can be nice if, for example, you have a UI backed by several different tracked objects, and you want to indicate if there are any changes that need to be saved.

I can do it manually using something like the above where I iterate over all tracked objects, call GetChangeTracker() on each one, and check ChangedProperties for any changes. But that requires keeping track of exactly which objects are being tracked and providing a common method to access them.

krispharper avatar Sep 20 '18 14:09 krispharper

@krispharper I see, something like ChangeTracker.HasChanges.

This involves a shared change tracker across many unrelated entities. It's related to #41

It requires some effort. Let me think again about it.

mfidemraizer avatar Sep 20 '18 18:09 mfidemraizer