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

Autoincrement Id is not read back [not an issue or question] #179

Closed Jogai closed 5 years ago

Jogai commented 5 years ago

Description

I found a bug in my usage of GraphDiff, but still want to let you know. I had this:

        if (id.HasValue)
        {
            _db.UpdateGraph(newEntity, up => up
                .OwnedCollection(n => n.Children, da => da
                    .OwnedEntity(e => e.GrandChild, te => te
                        .OwnedEntity(gc => gc.Prop)))                   
            );
        }

But since my id was 0 the check is true, thus my entity was inserted this way. Then on calling

            await _db.SaveChangesAsync();

The autoincremented id is not read back. This is not an issue for me as I was using the library wrong, but I was surprised graphdiff just does an insert. Maybe if it does its a good idea to re-materialize the object so the behaviour matches EF?

If you want me to provide you with further details I can extend this, but maybe its not worth pursuing. If so, feel free to close the issue.

Further technical details

JonathanMagnan commented 5 years ago

Hello @Jogai ,

Thank for letting us know, it's very appreciated and could help us in a future issue.

I believe we will close this one as I'm not sure how we could correctly handle id = 0. I'm not sure if I'm surprised or not that an insert has been done since an id = 0 usually mean a new entity.

Jogai commented 5 years ago

It did surprise me. But like you said, 0 means new entity usually, and that was the case now, so everything worked out in the end.