表格:
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获取所有带有其客户信息的文档?这个查询可以获取所有文档,但是客户信息为空(当然):
connection.Query<Document>("select Id, SomeText, CustomerId, CustomerName from Documents")...
编辑 - 类似但更高级的映射问题: Dapper中级映射