修剪字符串NHIBERNATE

时间:2013-01-31 22:54:42

标签: nhibernate

无法相信我没有找到答案,但你如何进行像

这样的查询
SELECT LTRIM(RTRIM("ColumnName")) FROM ....
NHibernate中的

感谢

1 个答案:

答案 0 :(得分:4)

以Bank为POCO为例:

public class Bank
{
  public virtual int    ID { get; set; }
  public virtual string City { get; set; }
  public virtual string Street { get; set; }
}

LTRIM(RTRIM...

有一种语法
Bank bank = null;
var session = ...;
var query = session.QueryOver<BankAddress>()
  .SelectList(l => l

    // properties ID, City
    .Select(c => c.ID).WithAlias(() => bank.ID)
    .Select(c => c.City).WithAlias(() => bank.City)  

    // projection Street 
    .Select(Projections.SqlProjection(               
        " LTRIM(RTRIM({alias}.Street)) as Street"  // applying LTRIM(RTRIM
        , new string[] { "Street" }
        , new IType[] { NHibernate.NHibernateUtil.String }
  ))
  .TransformUsing(Transformers.AliasToBean<Bank>())
  ;

var list = query.List<Bank>();