GraphDiff icon indicating copy to clipboard operation
GraphDiff copied to clipboard

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

Open mortb opened this issue 10 years ago • 0 comments

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")

mortb avatar May 06 '15 10:05 mortb