在.Net MVC 4 + Entity Framework 5中调用SP [英] Calling SP's in .Net MVC 4 + Entity Framework 5

查看:103
本文介绍了在.Net MVC 4 + Entity Framework 5中调用SP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的问题是,当我们使用ADO.Net命令调用时,我们可以从EF调用SP吗?如果是,请发一些示例代码。



我刚刚开始研究.Net MVC 4+ EF 5(ORM)。但是不知道EF是如何工作的。

EF是否优于ADO.Net对象?我是这种编码的新手。所以需要对此进行一些澄清。



先谢谢。



Jagadisha

Hi all,

My question is, can we call SP's from EF as we call using ADO.Net commands. If Yes, can you please post some sample codes.

I have just started working on .Net MVC 4+ EF 5(ORM). But don't have much idea how EF works.
Is EF is better than ADO.Net objects?. I am new to this type of coding. So need some clarification on this.

Thanks in Advance.

Jagadisha

推荐答案

这是一个填充下拉列表的简单示例!



DataContext是实体模型文件,您可以在其中拖放存储的内容过程,它反过来为MyStoredProcedureName SP生成自动代码,你可以像这样使用它。





Here is a simple example to populate a dropdownlist!

DataContext is the entity model file where you drag and drop your stored procedure which in turns generate automatic code for the MyStoredProcedureName SP and you can use it like this.


using(DataContext context = new DataContext())
{ 
                    var result = context.MyStoredProcedureName();
                    MyDropDownList.DataSource = result ;
                    MyDropDownList.DataBind();
}


这篇关于在.Net MVC 4 + Entity Framework 5中调用SP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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