nhibernatequeryovernhibernate-projections

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

Solution

  • 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)