问题描述
我在哪里可以得到实体框架很好的教程是存储过程的MVC框架?
Where can I get good tutorial on Entity framework with Stored Procedure in MVC framework?
它是更好的时候我几乎都写在存储过程中这种情况下,使用企业库。
Is it better to use Enterprise library in this case when I have almost everything written in the stored procedure.
请注意:我使用的存储过程,因为他们真的很复杂,其中有些是超过1000行
Note: I am using stored procedure because they are really very complex and some of them is over 1000 lines.
推荐答案
MVC在这种情况下,绝对没有关系的。你打电话是如何从EF存储过程的方式将仍然是相同的。我猜你想使用存储过程实际上并没有使用实体和LINQ到实体(主要EF功能),不是吗?一般来说,你需要:
MVC is in this case absolutely not related. The way how you call stored procedure from EF will be still the same. I guess you want to use stored procedures without actually using entities and linq-to-entities (main EF features), don't you? Generally you need:
- 你来自哪里,数据库运行更新,并添加您要使用的所有存储过程EDMX文件(ado.net实体数据模型)。 EDMX文件也产生衍生
的ObjectContext
,默认情况下所有实体。 - 接下来你必须去。功能导入将创建方法派生
的ObjectContext
这将允许您调用存储过程与任何其他.NET方法。 - 在功能导入你必须创建复杂的类型从存储过程返回的结果集(它可以自动发生)。
- EDMX file (ado.net entity data model) where you run update from database and add all stored procedures you want to use. EDMX file also generates derived
ObjectContext
and all entities by default. - Next you must go to Model Browser and create Function import for each procedure. Function import will create method on the derived
ObjectContext
which will allow you call the stored procedure as any other .net method. - During function import you will have to create complex type (it can happen automatically) for result set returned from stored procedure.
您也不必使用功能的进口都和这不,但它更像是直接做ADO.NET。
- Entity framework doesn't like stored procedures which returns dynamic result sets (based on some condition result set has different columns)
- Entity framework doesn't support stored procedures returning multiple result sets - there are EFExtensions which does but it is more like doing ADO.NET directly.
这篇关于如何通过EF调用MVC中的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!