テーブル:
create table Documents
(Id int,
SomeText varchar(100),
CustomerId int,
CustomerName varchar(100)
)
insert into Documents (Id, SomeText, CustomerId, CustomerName)
select 1, '1', 1, 'Name1'
union all
select 2, '2', 2, 'Name2'
クラス:
public class Document
{
public int Id { get; set; }
public string SomeText { get; set; }
public Customer { get; set; }
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
}
DapperDocuments
を使用してすべてを取得するにはどうすればよいですか? Customers
これにより、すべてのドキュメントが得られますが、顧客は null です (もちろん):
connection.Query<Document>("select Id, SomeText, CustomerId, CustomerName from Documents")...
編集 - 似ていますが、より高度なマッピングの質問: Dapper 中間マッピング