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; }
}
我怎样才能得到所有Documents
他们Customers
与小巧玲珑的?这给我的所有文件,但客户为空(当然):
connection.Query<Document>("select Id, SomeText, CustomerId, CustomerName from Documents")...
编辑 - 相似,但更先进的映射问题:从dapper project page拍摄(见多映射部分)Dapper intermediate mapping
提供,在这个问题,必要的SQL架构,C#类,以及当前的代码非常感谢。非常感谢,并提出了一个写得很好的问题。 – 2012-04-16 08:49:13
@MarcGravell:很好说。为这个事实+为这个问题+1,所以OP更加鼓励参与这个社区。 – 2012-04-17 07:10:15