Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get NHibernate QueryOver .SelectList(x) from Function

Is there a way to get a list of members from a function that can be passed in to SelectList()?

So instead of doing this

var dtos = repository.QueryOver<MicrofilmExportProcessed>()
                    .SelectList(list => list
                        .Select(x => x.Member1).WithAlias(() => dto.Member1)
                        .Select(x => x.Member2).WithAlias(() => dto.Member2)
                        .Select(x => x.Member3).WithAlias(() => dto.Member3))
                    .List<MicrofilmExportProcessed>();

Doing something like this:

var dtos = repository.QueryOver<MicrofilmExportProcessed>()
                    .SelectList(getMembersFromFunc())
                    .List<MicrofilmExportProcessed>();

I tried creating method that returns the same type as the input parameter of the SelectList but it still tells me the input type is invalid. Not sure what I'm missing.

like image 738
KingOfHypocrites Avatar asked Feb 21 '23 19:02

KingOfHypocrites


1 Answers

Something like

Func<QueryOverProjectionBuilder<InvoiceDto>, QueryOverProjectionBuilder<InvoiceDto>> GetList()
{
    InvoiceDto dto = null;
    return list => list.Select(w => w.Client).WithAlias(() => dto.Client);
}

and call it like

return Session.QueryOver<InvoiceDto>()
    .SelectList(GetList())
    .TransformUsing(Transformers.AliasToBean<InvoiceDto>())
    .List<InvoiceDto>();
like image 95
Rippo Avatar answered Mar 03 '23 01:03

Rippo