简体   繁体   English

从Function中获取NHibernate QueryOver .SelectList(x)

[英]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()? 有没有办法从函数中获取成员列表,可以传递给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. 我尝试创建方法,返回与SelectList的输入参数相同的类型,但它仍然告诉我输入类型无效。 Not sure what I'm missing. 不知道我错过了什么。

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>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM