NHibernate投影:如何将QueryOver投影到int列表中?

时间:2013-07-12 19:28:16

标签: nhibernate queryover nhibernate-projections

尝试将查询结果投影到整数列表中。怎么做到这一点?应该使用什么变压器。 AliasToBean不起作用,因为它需要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>();

2 个答案:

答案 0 :(得分:2)

另一种方式:

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

(一起摆脱TransformUsing

答案 1 :(得分:0)

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