我有一个像这样的存储过程:
CREATE STORED PROCEDURE Test1
AS
BEGIN
SELECT * FROM Table1
SELECT * FROM Table2
END
现在我想在EF中使用这个程序。怎么样?!我可以使用从 EF 中的过程返回的两个 SELECT 请求吗?!
注意:如果这个存储过程仅返回结果,我知道如何使用它
谢谢
这是你问题的答案
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();
}
}