更改实体框架中的继承类型 [英] Changing Inherited Types in Entity Framework

查看:101
本文介绍了更改实体框架中的继承类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这里有一个类似的问题,但我不认为这是非常清楚的,所以我正在创建另一个:实体框架:继承,更改对象类型



我有一个实体学生继承自实体人员。 p>

某些人可能会成为学生。



在实体框架4中有没有办法处理这个没有存储过程或创建新实体。

解决方案

否。 EF继承不支持这种情况。为现有的创建学生的最佳方式是使用存储过程


请注意,这不是通过映射连接到学生实体的存储过程,而是可以从代码显式调用的另一个。理想情况下,它将是一个采用 PersonID 作为参数的SP,使用 PersonID 将新行插入到 Student 表中,然后返回一个完整的学生,以便可以非常地使用。


I see there is a similar question asked here but I don't think it was very clear so I'm creating another : Entity Framework: Inheritance, change object type

I have an Entity Student that inherits from an Entity Person.

At some point a Person could become a Student.

Is there any way in Entity Framework 4 to handle this without a stored procedure or creating a new entity.

解决方案

No. The EF inheritance does not support this scenario. The best way to create a Student for an existing Person is to use a stored procedure.
Please note that this is not a stored procedure that is wired up to the Student entity through mappings, but a separate one that can be called explicitly from code. Ideally it would be a SP that takes a PersonID as a parameter, inserts a new row into the Student table using that PersonID, and then returns a complete Student so that it can be used immidiately.

这篇关于更改实体框架中的继承类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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