类继承自Entity Framework类,仍然可以使用继承的类映射来保留到DB中? [英] Can a class inherit from Entity Framework class and still persist back to the DB using the inherited classes mappings?
问题描述
我想要支持的方案是将Entity对象扩展到引用包含实体和映射的程序集的另一个程序集中。 Partials类和映射被编译到包含Entity对象的程序集中。所以我不能通过使用部分类完成这个。
不可以用EDMX(和自我跟踪实体)。如果要存储派生类型,它也必须进行映射。如果您需要添加任何生成的代码,请使用您自己的部分实体类。
令人惊讶的是,它看起来像代码优先(EFv4 .1和DbContext API),但在这种情况下,您不能使用自我跟踪实体。我刚检查数据库,并且代码优先也是不可能的。它默默地创建TPH继承,派生类被映射为另一个实体。
Can a class inherit from Entity Framework class and still persist back to the DB using the inherited classes mappings? I have received errors trying to derive from a 'Self-Tracking Entity' class when I try and SaveChanges stating that the Type does not have any mappings. I would have hoped since the Type was Inherited from the Entity class that it could also inherit the entity mappings somehow for this to work. Has anyone been able to get this to work?
The scenario I am trying to support is to extend the Entity object in another assembly that references the assembly containing the Entity's and mappings. Partials classes and mappings are compiled into the assembly containing the Entity objects. So I can't accomplish this through the use of partial classes.
No it is not possible with EDMX (and self tracking entities). If you want to store derived type it must be mapped as well. If you need to add anything to generated code use your own partial part of the entity class.
Surprisingly it looks like it is possible with code-first (EFv4.1 and DbContext API) but in such case you cannot use self tracking entities. I just checked database and it is not possible with code-first as well. It silently creates TPH inheritance and derived class is mapped as an another entity.
这篇关于类继承自Entity Framework类,仍然可以使用继承的类映射来保留到DB中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!