Greg
Greg

Reputation: 11480

Dapper Multi-Mapping

Inside the Dapper documentation I can clearly see the multi-mapping for a semi-simple object or simple object. For instance:

public class Post
{
     public int Id { get; set; }
     public string Name { get; set; }
     public User Owner { get; set; }
}

public class User
{
     public int Id { get; set; }
     public string Name { get; set; }
}

IDbConnection.QueryAsync<Post, User, Post>(query, (post, user) => { post.Owner = user; return post; }, new { Id = id }, null, true, "id", CommandType.Text);

The question, is how to have Dapper handle more complex objects that have more than one inner object. For instance:

public class PlotStemDomain
{
     public int Id { get; set; }
     ...
     public PlotDomain Plot { get; set; }
     public SpeciesDomain species { get; set; }
}

public class PlotDomain
{
     public int Id { get; set; }
     ...
}

public class SpeciesDomain
{
     public int Id { get; set; }
     ...
}

When it appears to only handle a single Func<Post, User, Post>.

Upvotes: 1

Views: 1855

Answers (1)

Void Ray
Void Ray

Reputation: 10209

Out of the box Dapper's Multi-Mapping supports about 7 objects to be mapped. An alternative, is to use QueryMultiple. See this thread for an example, it is very similar...

Upvotes: 1

Related Questions