zzzprojects / GraphDiff

GraphDiff is a library that allows the automatic update of a detached graph using Entity Framework code first.
https://entityframework-graphdiff.net/overview
MIT License
333 stars 101 forks source link

Generic Repository and Concurrency #53

Closed piedatt80 closed 10 years ago

piedatt80 commented 10 years ago

First of all congratulations for your extension method. My questions are the following: 1) I downloaded the latest version (1.3.6) package for my Generic Repository and I replaced the part concerning the Update: using RefactorThis.GraphDiff;

namespace DAL { public class GenericRepository : IGenericRepository where T : class, IEntityWithId { private MyContext ctx; private readonly DbSet dbSet; public GenericRepository(MyContext context) { ctx = context; dbSet = ctx.Set(); //disable LazyLoading and Proxy ctx.Configuration.LazyLoadingEnabled = false; ctx.Configuration.ProxyCreationEnabled = false; }

    public void Update(T entityToUpdate)
    {
        ctx.UpdateGraph(entityToUpdate);
    }

    /*
    public void Update(T entityToUpdate)
    {
        var entry = ctx.Entry<T>(entityToUpdate);

        if (entry.State == EntityState.Detached)
        {
            var set = ctx.Set<T>();

            T attachedEntity = set.Find(entityToUpdate.ID);

            if (attachedEntity != null)
            {
                ctx.Entry<T>(attachedEntity).CurrentValues.SetValues(entityToUpdate);
            }
            else
            {
                entry.State = EntityState.Modified;
            }
        }
    }
    */

With great enthusiasm I noticed that in every Form of my application, updates to work correctly. However when I create a situation where you might expect a concurrency conflict, I get the following error:

An unhandled exception of type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in RefactorThis.GraphDiff.dll

Additional information: RowVersion failed optimistic concurrency

In my Model in Code First is however a line for managing concurrency (Timestamp).

2) I downloaded the source code directly from the site https://github.com/refactorthis/GraphDiff/(Download ZIP) but once compiled, I noticed that this is no longer the 1.3.6 version but a version next time, I think it's the future 1.4.0 With this version, I can no longer compile the row currently ctx.UpdateGraph (entityToUpdate). Perhaps it should be error caused by the Abstract Class but I did not understand.

ghost commented 10 years ago

Hi,

you're correct, the source is the current version (1.4.0) and the NuGet package hasn't been updated to that version yet (please see issue #35). I hope the package will be updated soon.

The exception you're seeing is just indicating that a concurrency has occured, so I think everything works as expected. What exactly do you mean by this?

In my Model in Code First is however a line for managing concurrency (Timestamp).

How'd you like GraphDiff to behave differently in case of a concurrency?

The current code is very different than that for version 1.3.6 as there have been major refactorings. If you could clarify what you're trying to achieve, I may be able to provide some insight as to how to accomplish it..

Glad you like GraphDiff - thanks!

refactorthis commented 10 years ago

Package updated.