ADO.Net EF4 继承问题。从基础对象创建子对象
我有一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为现有
用户
创建Tutor
的唯一方法是使用存储过程; 不是通过映射连接到 Tutor 实体的存储过程,而是可以从代码显式调用的单独存储过程。理想情况下,SP 将 UserId 作为参数,使用该 UserId 在表中插入新行,然后返回完整的 Tutor 对象,以便可以立即使用。
The only way to create a
Tutor
for an existingUser
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.