实体框架中的存储过程 [英] Stored procedures in entity framework
问题描述
我试图在实体框架中使用一个没有返回任何内容的存储过程。存储过程完全用于记录。
I am trying to use a stored procedure in the entity framework that returns nothing. The stored procedure is purely for logging.
我添加了一个函数(右键单击 - > add - >函数导入),只有当返回值设置为实体。当我将返回类型更改为Int32,Bool或者没有任何东西,或任何其他值比实体时,函数(方法)只要我按下构建按钮就会消失。
I added a function (right click -> add -> function import) which works ONLY when the return value is set to one of the entities. When I change the return type to be Int32, Bool or nothing, or any other value than an entity, the function (method) simply vanishes as soon as I hit the build button.
任何有关如何获得排序的建议?
Any suggestions on how I can get this sorted?
推荐答案
现在你不能 - 你必须使用您的模型中定义的实体(虽然我认为基本的标量类型,如INT应该也可以工作)。
For now you cannot - you have to use one of the entities defined in your model (although I thought basic scalar types like INT should work, too).
事情应该会比EF4好多了 - 2010年初。
Things should get a lot better with EF4 - due out in late 2009 or early 2010.
有关这些新功能的一些信息,请参阅这些文章:
See these articles for some info on those new features:
- A big step for Stored Procedures in EF4
- Complex Types in the EDM Designer in EF4 and a look at updating complex types in code
如果您的存储过程纯粹用于记录,那么我可能只是在实体框架上下文,只是调用存储过程的好老式ADO.NET方式....为什么甚至把所有这一切放在EF上下文中?您不会使用此日志记录服务来检索,操作和存储数据 - 只需使静态方法成为静态类 - 保持简单!
If your stored proc is purely for logging, I would probably just surface it outside the Entity Framework context and just call the stored procedure the good old-fashioned ADO.NET way.... why even bother putting all of that into an EF context? You're not retrieving, manipulating and storing data with this logging service - just make it a static method on a static class - keep it simple!
Marc
这篇关于实体框架中的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!