문제

I have a Session.QueryOver, that I need to mantain, and I want to remove the magical strings for column names, something like:


return Session.QueryOver<T>()
    .SelectList(list => list
        .Select(Projections.SqlGroupProjection(
            "CANDIES(" + MagicalStringForColumnName +") As [Candies]",
            "CANDIES(" + MagicalStringForColumnName + ")",
            new[] { "Candies" },
            new IType[] { NHibernateUtil.Int32 }))

And I want it to be like:

return Session.QueryOver<T>()
    .SelectList(list => list
        .Select(Projections.SqlGroupProjection(
            "CANDIES(" + Session.GetColumnNameFromMappedProperty(propInfo.Name) +") As [Candies]",
            "CANDIES(" + Session.GetColumnNameFromMappedProperty(propInfo.Name) + ")",
            new[] { "Candies" },
            new IType[] { NHibernateUtil.Int32 }))
도움이 되었습니까?

해결책

Turns out, that with the use of alias and SqlFunction, one can use an expression, instead of a magical string.

        object a = null;

        return Session.QueryOver<T>()
               .SelectList(l =>
                   l.Select(
                   Projections.GroupProperty(
                   Projections.SqlFunction("CANDIES", NHibernateUtil.Int32, Projections.Property(expression))
                   )).WithAlias(() => a)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top