Custom collection support broken in EF6 beta1

Topics: EF Runtime
Aug 15, 2013 at 10:52 PM
I have existing code that assigns a collection of entities to a custom collection.
Something like this:

MyCollection : List<MyDetailObject>

and

class MyMasterObject
{
public virtual MyCollection Details
{
get;
set;
}
}

This no longer works. Instead I get an error: "This operation is only valid on generic types." when I access the collection.

However, if I redefine my custom collection like this:
class MyCollection<T> : List<T> where t: MyDetailObject

and my class like this:

class MyMasterObject
{
public virtual MyCollection<MyDetailObject> Details
{
get;
set;
}
}

it works. It's like EF6 isn't traversing the class definition anymore?
Developer
Aug 15, 2013 at 11:49 PM
@sgifford Thanks for reporting this! I have created the following work item for it: https://entityframework.codeplex.com/workitem/1566

The workaround is to set the navigation property in the entity constructor so that EF will not attempt to create an instance of the custom collection class. For example:
class MyMasterObject 
{
  public MyMasterObject 
  {
    Details = new MyCollection();
  }
 
  public virtual MyCollection Details   { get; set; } 
} 
Developer
Aug 16, 2013 at 7:53 PM
@sgifford I have checked in a fix. This should be in tonight's nightly build and and in the EF6 RTM. Unfortunately it is too late for the fix to be included in the upcoming RC release.

Thanks,
Arthur