Updates to GraphDiff with new scenarios supported

Hi, This post will just be a quick update on the progress of GraphDiff.

It’s great that quite a few people are using/looking into GraphDiff. I have finally found some time and I am updating the code with numerous bug fixes and new features. I will be able to spend more time on this project now so if you have any issues please add them to github here .

There is a new official package on nuget called ‘RefactorThis.GraphDiff’ the only breaking change is a namespace change from GraphDiff to RefactorThis.GraphDiff. This package is a newer version and will receive all future updates you can get it here .

I also want to quickly clarify what AssociatedCollection and AssociatedEntity does as I’ve had some questions.

Associated/Owned clarification

If a person has a list of friends and you want to update the list of a friends for a person, but not update the entities inside that collection (such as that friend’s first name) then that friend collection is an associated collection and can be written like this:

context.UpdateGraph(person1, map => map.AssociatedCollection(person => person.friends));

if an update has been made to the friend entity we don’t want it to be saved, however we do want to save the fact that the person now has a new friend. This is what the associated collection does. An owned collection on the other hand will state that all of the entities inside of the friends collection are owned by the parent entity and will be updated, so the first name change will be saved to the database.

For more information please read my original post here

New Features/Fixes

  • Supports cyclic navigational properties
  • Now only performs updates of the parent and nested entities when needed (better support for auditing and concurrency scenarios)
  • Bugfix for complex graphs of collections of collections
  • Supports proxy objects (no lazy loading is done from within GraphDiff, all entities needed are loaded with one query) however the code did not support proxy objects.
  • Supports reloading entities that have been attached with the GraphDiffConfiguration.ReloadAssociatedEntitiesOnAttach configuration option. This is useful in cases where you may want to return the graph once saved. EF (by design) will returned the attached object not the object as it truely is in the database as the object exists in its local cache. The easy way to get around this is to simply make the database calls on a new context. If this is unavailable to you then you can set this configuration option and GraphDiff will ensure that any associated entities are updated from the database, ensuring you always receive the latest copy of all entities.

6 thoughts on “Updates to GraphDiff with new scenarios supported

  1. Great job mate! I am just unclear on whether proxies are supported or not. Since your post reads “however the code did not support proxy objects”. I am looking forward to using your library. BTW, with Graphdiff plus Automapper, do you still find yourself coding repositories?

  2. In a generic repo, I try the code below and I get an error: at VisitMember Unable to cast object of type ‘System.Reflection.RtFieldInfo’ to type ‘System.Reflection.PropertyInfo’.

    public void Update(TEntity master, Expression<Func<TEntity, ICollection>> selector)
    db.UpdateGraph(master, map => map.OwnedCollection(selector));

    It is a short method so I may just need to deal with it. But I thought it may be of interest.

      • Hi Brent,
        While doing some research I found that to be an common situation for others, lacking the { get; set; }. But not in my case, they are all declared as properties not fields. I think what may be going on is that I first get (query) a “proxy” object, modify it and then update it. So my declaration is correct, but the actual object passed has some issue. I really don’t know enough details but that is my suspicion.

  3. Hello, I’m trying to use the last nuget package (v 1.3.4), but it tries to install EF 4.3.
    I’m currently using the latest 5.0 version, so the result is that when I try to run the code, I get an exception saying that the EF 4.3.1 could not be found.
    How can I solve this? Why is GraphDiff dependent on EF 4.3.1 ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s