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; }
}
どのように取得することができますDapperのとのCustomers
を持つすべてのDocuments
?これは私にすべての文書を与えるが、顧客は(もちろん)nullである:
connection.Query<Document>("select Id, SomeText, CustomerId, CustomerName from Documents")...
EDIT - 似ていますが、より高度なマッピング質問:dapper project pageから取らDapper intermediate mapping
、質問に、必要なSQLスキーマ、C#クラス、およびあなたの現在のコードを提供するための大きな感謝。それは非常に感謝し、非常によく書かれた質問のためになります。 –
@MarcGravell:非常によく言った。この事実だけのためにこの質問を+1したので、OPはこのコミュニティに参加することをさらに奨励します。 –