Mapping an non-primitive object with Dapper

dapper orm

Question

I have the following class

    public class Point
    {
        public long Id { get; set; }

        public Address Address { get; set; }
    }

I am attempting to have Dapper correctly map the Address data.

   var points = this._db.Query<Point>("select * from Points").ToList();

My table schema is as follows:

db schema

Is there any way to specify specific column data to Dapper, in order to map non-primitive objects? visual studio debugger image

Accepted Answer

In order to correctly map you need to use the multi-map functionality.

 var points = this._db.Query<Point, Address, Point>("select p.Id, 'x' [Id], p.Address_City [City], p.Address_State [State] from Points p", (p, a) =>
            {
                p.Address = a;
                return p;
            }).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