如何使用entityframework调用复杂类型存储过程的导入函数 [英] how to call import function of complex type stored procedure using entityframework
本文介绍了如何使用entityframework调用复杂类型存储过程的导入函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Asp.net的新手。如何在实体框架中使用存储过程?因为我使用复杂类型的存储过程来获取数据并在网格中显示它.SP需要单个参数。
任何人都可以给我在Asp.net和MVC4。
Hi,
I am new to Asp.net. How to use stored procedures in entity framework ? As i am using a stored procedure of complex type to get data and displaying it in a grid.The SP takes single parameter.
Can anyone give me the steps for doing this both in Asp.net and in MVC4.
推荐答案
转到模型浏览器
- >去你的模型商店
- >展开存储过程
- >右键单击您存储的程序
- >选择创建功能导入
或
转到模型浏览器
- >转到您的型号
- >展开您的实体容器
- >右键点击进口
- >选择创建函数导入
- >选择您要使用的存储过程
- >提供您的任何功能名称
- >选择您的存储过程的返回类型,如果它没有返回任何内容,请选择无
- >点击确定
任何问题评论plz
Go to Model Browser
-> Go To your Model Store
-> Expand Stored Procedures
-> Right Click On your stored Procedure there
-> Select Create Function Import
OR
Go to Go to Model Browser
-> Go To your Model
-> Expand Your Entity Container
-> Right Click Imports
-> Select Create Function Import
-> Select the Stored Procedure you want to use
-> Provide any name of your function
-> Choose your return type of your Stored Procedure , if its is not returning anything choose None
-> Click Ok
Any Prob Comment plz
编写如下代码并且工作原理
按钮点击
Wrote the code as below and it worked
In Button click
protected void Button1_Click(object sender, EventArgs e)
{
Student_BL scl = new Student_BL();
Guid gid = Guid.Parse(TextBox1.Text);
var y = scl.getstudent(gid);
GridView1.DataSource = (y.ToList<StudentR>());
GridView1.DataBind();
}
学生的业务层是。
The Business layer for student is.
public class Student_BL
{
SS1DBEntities2 obj = new Ss1DBEntities2();
public List<StudentR> getstudent(Guid gid)
{
System.Data.Objects.ObjectParameter Student1 = new System.Data.Objects.ObjectParameter("studentid",gid);
var x = obj.Student(Student1);
return x.ToList<StudentR>();
}
}
上下文类是
}
Context class is
public virtual ObjectResult<StudentR> Student(ObjectParameter studentId)
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<StudentR>("Student", studentId);
}
这是我提供的一个示例,我用过Northwind数据库的oyee表
这个是将复杂类型函数绑定到gridview的方法。
Here is a sample i'm providing,I've Used oyee table of Northwind database
This is the way you can bind complex type function to gridview.
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = EmployeeByCountry("UK");
GridView1.DataBind();
}
List<Employees> EmployeeByCountry(string Country)
{
List<Employees> EmpListObj = new List<Employees>();
NORTHWNDEntities NWEObj= new NORTHWNDEntities();
EmpListObj = NWEObj.EmployeeByCountry(Country).ToList<Employees>();
return EmpListObj;
}
-------
问候
Bikash
-------
Regards
Bikash
这篇关于如何使用entityframework调用复杂类型存储过程的导入函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文