dapper .net mapping with duplicate model properties for splitOn

.net dapper duplicates mapping

Question

I have two Model with same property name as

Class Office<br>
{
   int Id;
   string Name;
   Location Location;
}

Class Location
{
   int Id;
   string Name;
}

sqlConnection.Query<Office, Location, Office>("query", (o, l) => {o.Location=l}, splitOn="Id,Id").ToList();

How can i make it work.

Any help appreciated.

Popular Answer

well, you just forget return your new object in delegate

(o, l) => {o.Location=l; return o;}

i.e. you should wrote:

sqlConnection.Query<Office, Location, Office>("query", (o, l) => {o.Location=l; return o;}, splitOn="Id,Id").ToList();


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why