ADO.Net EF4 继承问题。从基础对象创建子对象

发布于 2024-10-05 09:44:00 字数 341 浏览 1 评论 0原文

我有一个简单的 EF4 实体模型,其中有一个基本实体 User 和一个子实体 Tutor。该应用程序要求任何新条目默认为User类型(基类),稍后可以升级为Tutor

所以基本上我希望将现有的 User 对象转换为 Tutor 对象。我想我可以通过使用现有用户的数据创建一个新的 Tutor 对象,添加额外的字段,删除旧的用户对象并尝试插入具有相同 ID 的新的 Tutor 对象来做到这一点。

有没有什么优雅的方法来实现这一点。

I have a simple EF4 Entity model in which i have a base Entity User and a child entity Tutor. The application demands that any new entry is by default of type User(base class) which later can be upgraded to a Tutor.

So basically i wish to convert a pre existing User object into a Tutor object. I think i can do it by creating a new Tutor object with data from existing User, add extra fields, delete the old user object and try inserting the new Tutor object with same Id.

Is there any elegant way to achieve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声 2024-10-12 09:44:00

为现有用户创建Tutor唯一方法是使用存储过程不是通过映射连接到 Tutor 实体的存储过程,而是可以从代码显式调用的单独存储过程。

理想情况下,SP 将 UserId 作为参数,使用该 UserId 在表中插入新行,然后返回完整的 Tutor 对象,以便可以立即使用。

The only way to create a Tutor for an existing User is to use a stored procedure; not a stored procedure that is wired up to the Tutor entity through mappings, but a separate one that can be called explicitly from the code.

Ideally it would be a SP that takes a UserId as a parameter, inserts a new row into the table using that UserId, and then returns a complete Tutor object so that it can be used immidiately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文