简体   繁体   中英

NHibernate projections: How to project QueryOver into list of int?

Trying to project query result into a list of integers. How does one do that? What transformer should be used. AliasToBean does not work as it requires setter.

var accessFeeYears = _session.QueryOver<AgreementAccessFee>()
                        .JoinAlias(a => a.FeeType, () => agreementAccessFeeTypeAlias)
                        .Where(x => x.Agreement.Id == request.AgreementId
                                                             && agreementAccessFeeTypeAlias.Code ==AgreementAccessFeeTypeCode.FlatChargePerInsured)
                         .SelectList(list => list
                                        .Select(a => a.PolicyYear).WithAlias(() =>policyYear))
                         .TransformUsing(Transformers.??????)
                         .List<int>();

Another way:

_session.QueryOver<AgreementAccessFee>()
    .JoinAlias(a => a.FeeType, () => agreementAccessFeeTypeAlias)
    .Where(x => x.Agreement.Id == request.AgreementId
        && agreementAccessFeeTypeAlias.Code == AgreementAccessFeeTypeCode.FlatChargePerInsured)
    .SelectList(list => list
        .Select(a => a.PolicyYear))
    .List<int>();

(get rid of the TransformUsing all together)

这很容易,看完选项后,PassThrough看起来会起作用,而且确实如此。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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