如何在SQL Server和Mars上使用ormlite?

c# dapper mars ormlite-servicestack

ServiceStack爱好者,你好!

我们是军团(我希望如此),所以请帮助一个兄弟:)

我试图用一个返回两个结果集的SQL Server 2008存储过程调用来填充两个集合。我的连接字符串中有“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;
          }
      }
 });

这可能吗?如果是这样,有人可以告诉我一个如何做到这一点的例子吗?

谢谢,

萨米尔

一般承认的答案

我找到了一种方法,但我不得不用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毫秒)。



许可下: CC-BY-SA with attribution
不隶属于 Stack Overflow
许可下: CC-BY-SA with attribution
不隶属于 Stack Overflow