Why I need to set the `SplitOn` parameter when I'm using a multi-mapping method with a key different than my id?

asp.net-mvc dapper

Question

I keep on getting this error. The place where it's throwing the error is:

 var projectManagerList = gridReader.Read<ProjectResources, Employee, ProjectResources>((pr, e) =>
                    {
                        pr.Employee = e;
                        return pr;
                    }).ToList();

The sql is:

 SELECT DISTINCT
                             p_Resources.Empl_ID as EmployeeId
                            ,p_Resources.cRole
                            ,p_Empl.ID as Id
                            ,p_Empl.Title
                            ,p_Empl.First_Name as FirstName
                            ,p_Empl.MI as MiddleInitial
                            ,p_Empl.Last_Name as LastName
                            ,p_Empl.Phone
                            ,p_Empl.PWD as Password
                            ,p_Empl.email as Email
                            ,p_Empl.LoginName
                            ,p_Empl.Admin
                      FROM   p_Empl
                         LEFT OUTER JOIN
                          p_Resources on p_Resources.Empl_ID = p_Empl.ID
                     WHERE  p_Resources.cRole='Project Manager' 

I wrote "as Id" so why is it throwing the error? Thanks.

1
2
6/8/2017 9:36:34 AM

Popular Answer

It tells you to set the splitOn parameter. So you should set it to Id.

var projectManagerList = gridReader.Read<ProjectResources, Employee, 
ProjectResources>((pr, e) =>
                {
                    pr.Employee = e;
                    return pr;
                },splitOn: "Id").ToList();

It tells you the split between ProjectResources and Employee is the Id column.

1
6/8/2017 10:39:48 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow