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

谁说我不能喝 提交于 2020-01-11 12:09:10

问题


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:


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.



来源:https://stackoverflow.com/questions/8351303/entity-framework-code-first-and-classes-that-implement-ilistt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!