Entity Framework Code First and Classes that Imple

2020-04-21 03:54发布

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?

1条回答
相关推荐>>
2楼-- · 2020-04-21 04:36

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.

查看更多
登录 后发表回答