0
列名

我有一個Session.QueryOver,我需要十個分量,我想刪除的神奇字符串列名,是這樣的:功能NHibernate - 從財產Session.QueryOver


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

而且我希望它像:

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

回答

1

事實證明,與使用別名和SqlFunction的,可以使用的,而不是一個神奇的字符串的表達式。

 object a = null; 

     return Session.QueryOver<T>() 
       .SelectList(l => 
        l.Select(
        Projections.GroupProperty(
        Projections.SqlFunction("CANDIES", NHibernateUtil.Int32, Projections.Property(expression)) 
        )).WithAlias(() => a)