存储过程 - 多种返回类型 [英] stored procedure- multiple return types
问题描述
我正在尝试将我的代码迁移到EF4,我需要帮助使用返回多个结果类型的存储过程。
在linq to sql中我通过使用"管理"来管理它; IMultipleResults " interface和" ResultType"如何在EF4中使用带有多种结果类型的sp?
Hi,
I am trying to migrate my code to EF4 and I need help using stored proc that returns multiple result types.
In linq to sql i managed doing it by using "IMultipleResults " interface and "ResultType" attribute.
How can I use sp with multiple results type in EF4?
[Function(Name = "dbo.P_USR_UserSummeryDetails")]
[ResultType(typeof(User))]
[ResultType(typeof(Operation))]
[ResultType(typeof(OrganizationUnit))]
[ResultType(typeof(OrganizationUnit))]
[ResultType(typeof(Role))]
[ResultType(typeof(User))]
[ResultType(typeof(User))]
public IMultipleResults GetUserSummeryDetails(int userID, string loginName, int fillMode)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), userID, loginName, fillMode);
return ((IMultipleResults)(result.ReturnValue));
}
推荐答案
恐怕还有没有开箱即用的支持存储过程返回多个结果。你可以使用翻译来帮助你。你是
var db = new ObjectContext();
I am afraid there is no out of the box support for stored procedure returning multiple result. You can use Translate to help u a bit.
var db = new ObjectContext();
string connstring = @"数据源= .;初始目录=测试;集成安全性=真;" ;;
string connstring = @"Data Source=.;Initial Catalog=Test;Integrated Security=True;";
var conn = new SqlConnection(connstring);
var conn = new SqlConnection(connstring);
var cmd = conn 。 CreateCommand();
var cmd = conn.CreateCommand();
cmd 。 CommandType = CommandType 。 StoredProcedure;
cmd.CommandType = CommandType.StoredProcedure;
cmd 。 CommandText = " GetBidDetails" ;
cmd.CommandText = "GetBidDetails";
conn 跨度>打开( );
conn.Open();
< span style ="font-family:Batang"> var reader = cmd 。 ExecuteReader(CommandBehavior 。 CloseConnection);
var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
< span style =""> var 出价 = db 。翻译< 出价> (读者,"出价" ,MergeOption 。 AppendOnly)。 ToList() ;
var bids = db.Translate<Bid>(reader, "Bids", MergeOption.AppendOnly).ToList();
读者。 NextResult();
reader.NextResult();
db 。翻译< 作业> (读者," Jobs" ,MergeOption 。 AppendOnly)。 ToList();
Zeeshan Hirani
db.Translate<Job>(reader, "Jobs", MergeOption.AppendOnly).ToList();
Zeeshan Hirani
这篇关于存储过程 - 多种返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!