开发者

Linq to Nhibernate 3.1 Group By (Or distinct)

开发者 https://www.devze.com 2023-03-09 17:41 出处:网络
I need to do a simple \"group by\" with a nhibernate query. My try were : (from adn in session.Query&l开发者_StackOverflowt;Table>()

I need to do a simple "group by" with a nhibernate query.

My try were :

(from adn in session.Query&l开发者_StackOverflowt;Table>()
        orderby adn.Data
        select adn.Data).Distinct().ToList<string>();

and

 session.Query<Table().GroupBy(adn => adn.Data).Select(dat => dat).ToList<string>()

can someone help me to find a solution ? My goal is to retrieve all the Distinct "Data" Column. It can be by group by or distinct.

(the 2 solutions would be better for my progression in nhibernate)

Regards

edit

Danyolviax, I tryied your solution

        return (from adn in session.Query<Table>()
                group adn by adn.Data into dataGroupe
                select dataGroupe).ToList<string>();

It doesn't work. I feared that I use Nhibernate 3.1 (and not 2.1)

Any correction or alternative solution ?

edit 2

In the second solution which works (^^)

I have a list of a class with one property. In my case, I prefer to have a list of string or int. Otherwise I should create a specific class for this case.

Do you know a trick.

And thanks for your support.


Look here:

Linq to NHibernate and Group By

here some examples:

http://msdn.microsoft.com/en-us/vcsharp/aa336754

updated

try this with 3.1.0.4000:

   var ret = (from adn in session.Query<Table>()
              group adn by adn.Data into dataGroup
              select new {dataGroup.Key }).ToList();

update

var ret = (from adn in session.Query<Table>()
           group adn by adn.Data into dataGroup
           select dataGroup.Key).ToList<string>();
0

精彩评论

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