本文介绍了如何使用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.
推荐答案
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);
}
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调用复杂类型存储过程的导入函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!