Entity Framework Code First and Classes that Implement IList<T>

I have a ComplexType that must implement IList<T> (background info here).

Unfortunately, Entity Framework complains about the indexed property required of that interface

[NotMapped]
public T this[int index]

(Note it's decorated with the NotMapped data annotation).

I get a DbUpdateException at runtime with the inner exception

Indexed properties are not supported.

If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected.

Is there some way for a complex type to implement IList<T> to be persisted by Entity Framework Code First?

Answers


Entity framework doesn't support open generic entities and I believe the same is true for complex types. The only way is to define specific type derived from closed generic type as you shown in your linked question.

Also there is some well known bug that mapped class must not have indexer.


Need Your Help

HDF gzip compression vs. ASCII gzip compression

c gzip hdf5

I have a 2D matrix with 1100x1600 data points. Initially, I stored it in an ascii-file which I tar-zipped using the command