Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OwnedCollection crashes for custom collection types #155

Open
Jerther opened this issue Jan 13, 2016 · 5 comments
Open

OwnedCollection crashes for custom collection types #155

Jerther opened this issue Jan 13, 2016 · 5 comments

Comments

@Jerther
Copy link

Jerther commented Jan 13, 2016

When calling OwnedCollection on a custom collection, I get the following error:

GraphDiff requires the collection to be either IEnumerable or T[]

The custom collection is something like:

class FooCollection : List<Foo>

The error seems to from this code:

CollectionGraphNode
private Type GetCollectionElementType()
{
    if (Accessor.PropertyType.IsArray)
    {
        return Accessor.PropertyType.GetElementType();
    }

    if (Accessor.PropertyType.IsGenericType)
    {
        return Accessor.PropertyType.GetGenericArguments()[0];
    }

    throw new InvalidOperationException("GraphDiff requires the collection to be either IEnumerable<T> or T[]");
}

Is there a workaround for this?

@Jerther
Copy link
Author

Jerther commented Jan 13, 2016

For now I've figured I could declare my class like so as a workaround:

class FooCollection<T> : List<Foo>
  where T : Foo

But I think we'll agree that we'd rather not do that... :)

@kotylo
Copy link

kotylo commented May 26, 2016

Just modify the source code and add:

if (Accessor.PropertyType.BaseType.IsGenericType)
{
    return Accessor.PropertyType.BaseType.GetGenericArguments()[0];
}

throw new InvalidOperationException("GraphDiff requires the collection to be either IEnumerable<T> or T[] or derived from GenericType");

I've added simple test for this and others were still green. Also it worked on my DB.

@Jerther
Copy link
Author

Jerther commented May 26, 2016

Thanks!!

I know you stopped supporting the project, but is there any chance for this to make it to the NuGet package?

@Dvornik
Copy link

Dvornik commented May 26, 2016

@kotylo Thank you! Could you add a pull request with this modification and test, please?

@kotylo
Copy link

kotylo commented May 26, 2016

@Dvornik, I just checked this on my collection. The fix may not be that simple, but it works for my simple entities.
Created pull request here https://github.com/refactorthis/GraphDiff/pull/161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants