如何在SQL Server和Mars中使用ormlite?
作者:互联网
ServiceStack爱好者,您好!
我们是军团(我希望如此),所以请帮助一个兄弟:)
我试图用一个返回两个结果集的SQL Server 2008存储过程调用填充两个集合.
我的连接字符串中有“ MultipleActiveResultSets = True”,但仍然出现此错误:
‘r.NextResult()’ threw an exception of type
‘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;
}
}
});
这可能吗?如果是这样,有人可以给我示范一个例子吗?
谢谢,
萨米尔
解决方法:
我找到了一种方法,但是我不得不用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改善之前的速度快(从40毫秒到20毫秒).
标签:dapper,ormlite-servicestack,mars,c 来源: https://codeday.me/bug/20191201/2077478.html