我有一个存储过程:
CREATE PROCEDURE uspGetData
...Parameter
AS
SELECT 'hello' AS 'HelloColumn'
GO
然后我使用ObjectContext
来执行存储过程
((IOjbectContextAdapter)this).ObjectContext.ExecuteFunction<HelloClass>("uspGetData", .... Parameter);
HelloClass
只是一个数据类
public class HelloClass
{
public string HelloColumn { ... }
}
我得到了我需要的完美结果
但现在我需要在存储过程中添加另一个SELECT
,如下所示
CREATE PROCEDURE uspGetData
...Parameter
AS
SELECT 'hello' AS 'HelloColumn'
SELECT 'byebye' AS 'ByeColumn'
GO
当然,在真实环境中更复杂,不仅仅是SELECT something
现在我无法得到我需要的结果,
我尝试在HelloClass
public class HelloClass : ByeClass
{ ... }
我也尝试在ObjectContext
命令
((IOjbectContextAdapter)this).ObjectContext.ExecuteFunction<HelloClass,ByeClass>...
无论如何都要从存储过程中设置两个结果吗?
答案 0 :(得分:0)
是的,有办法。
using (var db = new YourContext())
{
var cmd = db.Database.Connection.CreateCommand();
cmd.CommandText = "YourStoredProcedure";
db.Database.Connection.Open();
var reader = cmd.ExecuteReader();
ObjectResult<HelloClass> table1 = ((IObjectContextAdapter)db).ObjectContext.Translate<HelloClass>(reader, "HelloClass", MergeOption.AppendOnly);
reader.NextResult();
ObjectResult<HelloClass2> table2 = ((IObjectContextAdapter)db).ObjectContext.Translate<HelloClass2>(reader, "HelloClass2", MergeOption.AppendOnly);
}
了解更多信息请查看: https://msdn.microsoft.com/en-us/data/jj691402.aspx