C#dapper - 如何获得2个不同的复杂对象表?

时间:2017-11-19 07:33:38

标签: c# sql sql-server dapper

您好我正在使用Dapper,我需要获得2个表 - 代表2个复杂对象

例如:(当然我的代码有更多的逻辑,但它只是一个例子)

var toys=new List<toy>(); // toy is a complex object 
var smartphones = new List<Smartphone>(); // smartphone is a complex object

我希望通过一次调用DB获得这2个列表。

现在,我知道如何获得一个复杂对象列表:

 using (IDbConnection db = AdoExtension.GetConnection())
        {
            boardOrder = db.Query
                ("sp_GetBoardParentByID",
               new[]
               {
                    typeof(BoardOrderVM),
                    typeof(Status),
                    typeof(Country),
                    typeof(Manager),
                    typeof(ManagerType),
                    typeof(BusinessLine),
                    typeof(Project),
                    typeof(Branch)
               },
               objects =>
               {
                   BoardOrderVM board = objects[0] as BoardOrderVM;
                   Status status = objects[1] as Status;
                   Country country = objects[2] as Country;
                   Manager mng = objects[3] as Manager;
                   ManagerType mngType = objects[4] as ManagerType;
                   BusinessLine bline = objects[5] as BusinessLine;
                   Project proj = objects[6] as Project;
                   Branch branch = objects[7] as Branch;

                   board.Status = status;
                   board.Country = country;
                   board.ApprovingManager=mng ;
                   board.ManagerType = mngType;
                   board.BusinessLine = bline;
                   board.Project = proj;
                   board.Branch = branch;                     

                   return board;
               }
                , commandType: CommandType.StoredProcedure
                // single - we want to get o-n-l-y one order
                , splitOn: "ID, ,ID , CountryName, Name, Type, Name, Description, Name", param: p).Single();
        }

但是如何获得2个不同的复杂对象表?

提前致谢

0 个答案:

没有答案