How to specify the columns in a MultiMap query instead of using * (asterisk)

dapper

Question

Sometimes I don't want to fill my entities entirely (some properties are not always necessary), but, how can I specify the table columns in a MultiMap query?

Just an example:

Table Costumer ID (PK) Name Address CityID (FK to Table City, column ID) Email

Table City ID (PK) Name State

I need to use a query like this:

    SELECT Costumer.ID, Costumer.Name, Costumer.Email, City.ID AS CityID, City.Name AS CityName
    FROM Costumer INNER JOIN City ON Costumer.CityID = City.ID

My question is: how can I specify the join columns without having name conflict and having dapper to identify the mapping between the columns and the entity's properties?

Accepted Answer

With the clarifications in the comments, it should work something like:

var custs = conn.Query<Customer,City,Customer>(sql,
       (cust,city) => { cust.City = city; return cust; },
       splitOn: "ID,CityID").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