我有一个这样的存储过程:
CREATE STORED PROCEDURE Test1
AS
BEGIN
SELECT * FROM Table1
SELECT * FROM Table2
END
现在我想在EF中使用这个程序。怎么样?!我可以使用从EF中的过程返回的两个SELECT请求吗?!
注意:我知道如果只返回结果
,我该如何使用这个存储过程由于
答案 0 :(得分:3)
以下是您的问题的答案
using (var db = new EF_DEMOEntities())
{
var cmd = db.Database.Connection.CreateCommand();
cmd.CommandText = "[dbo].[proc_getmorethanonetable]";
try
{
db.Database.Connection.Open();
using (var reader = cmd.ExecuteReader())
{
var orders = ((IObjectContextAdapter)db).ObjectContext.Translate<Order>(reader);
GridView1.DataSource = orders.ToList();
GridView1.DataBind();
reader.NextResult();
var items =
((IObjectContextAdapter)db).ObjectContext.Translate<Item>(reader);
GridView2.DataSource = items.ToList();
GridView2.DataBind();
reader.NextResult();
var collect = ((IObjectContextAdapter)db).ObjectContext.Translate<object>(reader);
GridView3.DataSource = collect.ToList();
GridView3.DataBind();
}
}
finally
{
db.Database.Connection.Close();
}
}