Linq to Nhibernate 3.1 Group By (Or distinct)
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>();
精彩评论