使用 DbContext Generator 时有什么方法可以获得函数导入支持吗?
我正在尝试使用新的 Entity Framework 4.1 DbContext Generator,因为它为所有实体生成非常干净的 POCO 类,并且它使用 DbContext API 而不是 ObjectContext API。我遇到的问题是,似乎无法在 DbContext API 中映射“函数导入”(或至少使用生成器)。是否无法通过 DBContext API 使用存储过程进行函数导入,或者我只是做错了什么?
谢谢
更新 我认为这是可能的,但我需要弄清楚如何获取 DbContext API 的底层 ObjectContext,至少有人知道如何做到这一点吗?
I am trying to use the new-ish Entity Framework 4.1 DbContext Generator because it generates very clean POCO classes for all of the entities, and it uses the DbContext API instead of the ObjectContext API. The problem I am having is that there appears to be no way to map "Function Imports" in the DbContext API (or at least using the generator). Is it not possible to use stored procedures for function imports with the DBContext API, or am I just doing something wrong?
Thanks
UPDATE
I think that this is possible, but I would need to figure out how to get at the underlying ObjectContext of the DbContext API, anyone know how to do that at least?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我继续采用这种方法:
YourContext.Context1.cs
文件(使用 DbContext Generator)将此属性添加到
YourContext
的分部类中:使用函数导入在
.edmx
中设置 SP将每个 SP 的函数添加到
YourContext
类,例如I went ahead with this approach:
YourContext.Context1.cs
file (using the DbContext Generator)Add this property to the partial class for
YourContext
:Set up your SPs in the
.edmx
using function importAdd a function for each of your SPs to the
YourContext
class, e.g.至少 EF 4.1 的代码优先方法 不支持映射到存储过程:
但是你似乎采用模型优先/数据库优先的方法。我不知道是否有解决方案。人们可能会猜测有一种方法,因为它只是说Code-First 不支持 SP 映射,
您可以通过以下方式从
dbContext
实例访问底层ObjectContext
:At least the Code-First approach of EF 4.1 doesn't support mapping to Stored Procedures:
But you seem to go Model-First/Database-First approach. I don't know if there is a solution. One could guess there is a way, since it is only said that Code-First doesn't support SP mapping.
And you can access the underlying
ObjectContext
from yourdbContext
instance this way: