ServiceStack爱好者们,大家好!
我们是军团(我希望如此),所以请帮助一个兄弟:)
我正试图用一个返回两个结果集的SQLServer2008存储过程调用来填充两个集合。我的连接字符串中有"MultipleActiveResultSets=True",但我仍然收到这个错误:
"r.NextResult()"引发了类型为的异常"System.InvalidOperationException"
这是我的代码:
IList<ProjectMember> projectMembers = null;
IList<Project> projects = DbFactory.Run(dbCnx =>
{
using (var dbCmd = dbCnx.CreateCommand())
{
dbCmd.CommandType = CommandType.StoredProcedure;
dbCmd.CommandText = "mySchema.myStoredProc";
dbCmd.Parameters.Add(new SqlParameter("@categoryId", categoryId));
using (profiler.Step("ProjectService.myStoredProc"))
{
var r = dbCmd.ExecuteReader();
projectMembers = r.ConvertToList<ProjectMember>();
return r.NextResult() ? r.ConvertToList<Project>() : null;
}
}
});
这可能吗?如果是的话,有人能给我举个例子吗?
谢谢,
Samir
我找到了一种方法,但我不得不用Dapper:替换ormLite
using(var cnx = DbFactory.CreateConnection(Global.ConnectionString))
{
using (var multi = cnx.QueryMultiple("mySchema.myStoredProc", new { communityId, categoryId }, commandType: CommandType.StoredProcedure))
{
var projectMembers = multi.Read<ProjectMember>().ToList();
var projects = multi.Read<Project>().ToList();
BindProjectMembers(projects, projectMembers);
return projects;
}
}
它工作得很好,速度是MARS改进前的两倍(从40ms到20ms)。