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

Fix adding duplicate entities #174

Closed om2804 closed 4 years ago

om2804 commented 6 years ago

Issue #116. I tried to fix it, but entity need implement equality members now.

om2804 commented 6 years ago
public class ModelLevel2
    {
        protected bool Equals(ModelLevel2 other)
        {
            return Code.Equals(other.Code);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != this.GetType()) return false;
            return Equals((ModelLevel2) obj);
        }

        public override int GetHashCode()
        {
            return Code.GetHashCode();
        }

        public Guid Code { get; set; }
        public string Name { get; set; }
    }
JonathanMagnan commented 6 years ago

Hello @om2804 ,

Do you think you could provide us a test project with this issue?

It will make easier/faster for my developer to getting started for investigating it.

We now always ask for a project since we found out that most issues are missing some essential information or are resolved by the requestor when creating it

(Even if the issue seem very easy to reproduce, by getting a test project, it allow us to give a faster support and better experience for the support of all our free libraries)

Best Regards,

Jonathan

JonathanMagnan commented 6 years ago

Oops sorry, that's a pull ;)

We will review it.

JonathanMagnan commented 4 years ago

Hello @om2804 ,

Thank you for the fix,

We partially merged your pull. We choose to accept the part about the duplicate adding which indeed is a very good fix. However, we didn't accept the second part about 2 entity with the same id, we still added the code in comment because we might eventually give an option so people could choose to enable it or not.

Thank a lot for your contribution ;)

Best Regards,

Jon