开发者

using HQL to concatenate strings from multiple rows

Consider a table 开发者_如何学Cholding names, with three rows:

Peter Paul Mary

using NHibernate HQL I want to retrieve all the names as a single string "Peter, Paul, Mary" to put it inside a single DTO object field. is there a way to do this kind of concatenation?


No, there isn't.

It's not possible to do string column aggregation in SQL, except maybe by using specific RDBMS features.

Just bring all the names and concatenate them client-side,


It is too simple to implement this in C#, so it's not worth to try too hard to tweak NHibernate to do it (you may use functions or formula or ...)

class MyDto
{
  string Name1 { get; set; }
  string Name2 { get; set; }
  string Name3 { get; set; }

  string Names
  { 
    get 
    {
      return string.Format("{0}, {1}, {2}", Name1, Name2, Name3)
    }
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜