2017-04-26 171 views
1

在Dapper文檔中,我可以清楚地看到半簡單對象或簡單對象的多重映射。例如:Dapper多重映射

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); 

問題是如何使Dapper處理具有多個內部對象的更復雜的對象。例如:

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; } 
    ... 
} 

當它似乎只處理一個單一的Func<Post, User, Post>

回答

1

開箱即用Dapper的多重映射支持大約7個要映射的對象。另一種方法是使用QueryMultiple。以thread爲例,它非常相似...