在实体框架中存储proc [英] store proc in entity framework

查看:90
本文介绍了在实体框架中存储proc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为在EF中实现存储过程会不那么痛苦但事实并非如此......这对于执行存储过程非常困难,实际上直到现在还没有一个商店proc我设法执行!


实现存储过程的方法有多少?到目前为止,我找到了3种方法:


1)
http://www.robbagby.com/entity-framework/entity-framework-modeling-select-stored-procedures/
 


2) http://msdn.microsoft.com/en-us/vcsharp/dd565862.aspx


3) http://msdn.microsoft.com /en-us/library/bb896274.aspx


这个EF总是一场噩梦!

解决方案

另一方面,我发现EF和它对存储过程的支持非常有用。


AFAIK,有两种方法可以使用存储过程和EF。 / p>


  • 我们可以(并且应该)为表上的常规插入,更新和删除操作定义SP,并要求EF使用这些SP(而不是它的动态SQL)代)。
  • 我们可以使用特殊用途的SP作为FunctionImports。我发现这在我自己的项目中非常有用。例如,我有一个Hierarchy表(Id,ParentId,Name,Path)。每当用户更改Name属性时,我都必须为子节点更新所有
    的Path属性。这可以很容易地在T-Sql中完成而不是EF,所以我写了一个SP并为此创建了一个FunctionImport。 


i thought i would be less painful implementing store proc in EF but that's not the case.. it's been greatly giving me a hard time just to execute a stored proc and in fact up until now not even a single stores proc i managed to execute!

how many ways of implementing stored proc?? so far i have found 3 ways:

1) http://www.robbagby.com/entity-framework/entity-framework-modeling-select-stored-procedures/ 

2) http://msdn.microsoft.com/en-us/vcsharp/dd565862.aspx

3) http://msdn.microsoft.com/en-us/library/bb896274.aspx

This EF is a total nightmare!

解决方案

On the other hand, I found both EF and it's support for Stored Procedures very useful.

AFAIK, there are 2 ways we can use Stored Procedures with EF.

  • We can (and should) define SPs for regular Insert, Update and Delete operations on a table, and ask EF to use these SPs (instead of it's dynamic SQL generation).
  • We can use special-purpose SPs as FunctionImports. I found this very useful in my own projects. For example, I have a Hierarchy table (Id, ParentId, Name, Path). Whenever the user changes the Name property, I have to update the Path property for ALL the children. This can easily be done in T-Sql than EF, so I wrote an SP and created a FunctionImport for that. 


这篇关于在实体框架中存储proc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆