实体框架代码首先和实现IList的类< T> [英] Entity Framework Code First and Classes that Implement IList<T>

查看:77
本文介绍了实体框架代码首先和实现IList的类< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ComplexType ,必须实现 IList< T> background info here )。

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]

(注意它使用 NotMapped 数据进行装饰注释)

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

我在运行时得到一个 DbUpdateException ,内部异常

I get a DbUpdateException at runtime with the inner exception


不支持索引属性。

Indexed properties are not supported.

如果我注释到该类实现 IList< T> 并注释掉索引的属性,类的实例按预期方式保持不变。

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

是否有一些复杂类型的方式实现 IList 由Entity Framework持久化代码优先?

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

推荐答案

实体框架不支持打开的通用实体,我相信对于复杂类型也是如此。唯一的方法是定义从关闭通用类型派生的特定类型,如您所链接的问题所示。

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.

这篇关于实体框架代码首先和实现IList的类&lt; T&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆