改变的(实体框架)实体是继承层次结构的组成部分的类型 [英] Changing the type of an (Entity Framework) entity that is part of an inheritance hierarchy

查看:243
本文介绍了改变的(实体框架)实体是继承层次结构的组成部分的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基础Employee实体和一些派生实体特定员工类型的继承层次。我需要能够在基座雇员实体转换为更具体的实体(如TemporaryEmployee)和更具体的类型回基本类型(例如,如果员工不再是暂时的,那么我想该实例只是坚持为员工。 在DB这是从表添加或删除的行的特定的子类的问题而已。 (我使用表每类。)我没有看到如何做到这一点使用EF虽然调用。

I have an inheritance hierarchy with a base Employee entity and some descendent entities for specific employee types. I need to be able to convert a base Employee entity to a more specific entity (e.g. TemporaryEmployee) and from a more specific type back to the base type (e.g. if an employee is no longer "temporary" then I want that instance to just be persisted as Employee. In the DB this is just a matter of adding or removing a row from the table for the specific subclass. (I'm using table per class.) I'm not seeing how to do this using EF calls though.

推荐答案

从技术上讲,你可以通过使用存储过程实现的。 TPT不支持它。

Technically, you can achieve it by using the stored procedure. TPT does not support it.

不过,我完全同意克雷格。在经典的编程书籍设计模式(艾迪生韦斯利专业版),作者讨论了继承与组成,得出结论,应该​​有利于组成了继承。

However, I totally agree with Craig. In classic programming book Design Patterns (Addison-Wesley Professional), authors discuss inheritance versus composition and conclude that one should "favor composition over inheritance."

这篇关于改变的(实体框架)实体是继承层次结构的组成部分的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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