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

CollectionGraphNode.RemoveElement doesn't work if ownedcollection is an array #139

Open mortb opened 9 years ago

mortb commented 9 years ago

RemoveElement won't work if the collection is an array

    private void RemoveElement(IChangeTracker changeTracker, object dbItem, object dbCollection)
    {
        dbCollection.GetType().GetMethod("Remove").Invoke(dbCollection, new[] { dbItem });
        changeTracker.AttachRequiredNavigationProperties(dbItem, dbItem);

        if (_isOwned)
        {
            changeTracker.RemoveItem(dbItem);
        }
    }

Well this may be a bit uncommon, but I mocked the database using https://effort.codeplex.com/ I attached nested collections to my entities as arrays. When removing child objects in the arrays and calling UpdateGraph with ownedcollection the above code fails as there is no Remove method on the Array class. It just threw a "nullref" excpetion wich was a bit unspecific.NotSupportedExcpeiton for removing items in arrays would have been better :)

The reason I got this far is that there is support for arrays in AttributeGraphBuilder. I think it would also throw if I'd added an object as this does GetMetod("Add")