实体框架CTP5 - 如何调用存储过程?
这可能是一个简单的答案,但我看不到如何使用 EF CTP5 执行存储过程。
在 Entity Framework 4.0 中,我们这样做:
ExecuteFunction("ContainerName.StoredProcName", new ObjectParameter("Id", id))
。
这是ObjectContext
上的一个方法。
但是DbContext
没有这样的方法。
我们如何调用存储过程? EF CTP5 不支持吗?
编辑:
我发现
var people = context.People.SqlQuery("EXECUTE [dbo].[GetAllPeople]");
这引起了一些问题:
1) 您现在正在集合上调用存储过程,而不是上下文嗯>。存储过程应该在上下文范围内可用,而不是绑定到特定的实体集。就像它们在 SQL Server 中的“数据库”下,而不是在“表”下一样。
2)复杂类型怎么样?我以前有一个从存储过程返回的复杂类型。但现在,看起来好像你必须直接映射到一个实体?这没有任何意义。我有许多存储过程返回一个不直接由 ObjectSet/DBSet 表示的类型,我不知道如何将其拉过来。
希望有人能为我解决这个问题,因为据我所知,我将无法升级到 CTP5。
This may be a simple answer, but i can't see how to execute a stored procedure with EF CTP5.
In Entity Framework 4.0, we did this:
ExecuteFunction("ContainerName.StoredProcName", new ObjectParameter("Id", id))
.
Which is a method on the ObjectContext
.
But DbContext
has no such method.
How do we call a stored proc? Is it not supported in EF CTP5?
EDIT:
I found this thread, which states you need to do this:
var people = context.People.SqlQuery("EXECUTE [dbo].[GetAllPeople]");
This raises some concerns:
1) You are now calling a stored prodedure on the set, not the context. Stored procedures should be available context-wide, not tied to a particular entity set. Just like how they are under the "Database" in SQL Server, and not under the "Table".
2) What about complex types? I previously had a complex type being returned from a stored procedure. But now, it looks as though you have to map directly to an entity? That doesn't make any sense. I have many stored procs that return a type not directly represented by an ObjectSet/DBSet, which i can't see how i can pull over.
Hope someone can clear this up for me, because from what i understand so far, i won't be able to upgrade to CTP5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样执行数据库范围的sql语句
You can execute database-wide sql statements like this