First lets look at the QueryOver method. As you can see I have a method call named GetDtoList()
return Session.QueryOver<InvoiceDto>()
.SelectList(GetDtoList())
.TransformUsing(Transformers.AliasToBean<InvoiceDto>())
.List<InvoiceDto>();
Now for the GetList method. As you can see we return a Func of QueryOverProjectionBuilder. In the code we simply build the list as we normally would and just return it:-Func<QueryOverProjectionBuilder<InvoiceDto>,
QueryOverProjectionBuilder<InvoiceDto>> GetDtoList() {
InvoiceDto dto = null;
return list => list
.Select(w => w.ClientName).WithAlias(() => dto.ClientName)
.Select(w => w.InvoiceDate).WithAlias(() => dto.InvoiceDate)
.Select(w => w.InvoiceId).WithAlias(() => dto.InvoiceId);
}
Pretty nice I think although the use case for this may be a little limited. The next challenge is to use this when we join to another entity i.e.return Session.QueryOver<Invoice>()
.JoinQueryOver<Client>()
.SelectList(GetDtoList())
.TransformUsing(Transformers.AliasToBean<InvoiceDto>())
.List<InvoiceDto>();
No comments:
Post a Comment