I'm trying a quite simple mapping using Dapper. It is kind of One to One result set. Here is the simplified version of what I would like to do:
Classes:
public class Person
{
public string Name { get; set; }
public string LastName { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string Town { get; set; }
}
I get the data from a View/Strored Proc like this:
SELECT street, name, lastname, town from someProc
Is there a way to map this in one step, maybe like this?
//trying to get a List of Persons including mapped Addresses
connection.Query<Person>()
Any suggestions?
I figured it out by myself... So for those googling this:
Combine Dapper.Mapper (NuGet package) and a SplitOn field in your result set.
The result data should be ordered by objects (columnwise) and you can either use an Id or a "virtual field" ('' as id) as a splitter.
The "3rd object" idea is stupid.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.