Linq to Nhibernate 3.1 Group By(或不同)
我需要用 nhibernate 查询做一个简单的“group by”。
我的尝试是:
(from adn in session.Query<Table>()
orderby adn.Data
select adn.Data).Distinct().ToList<string>();
吗
session.Query<Table().GroupBy(adn => adn.Data).Select(dat => dat).ToList<string>()
有人可以帮助我找到解决方案 ? 我的目标是检索所有不同的“数据”列。 它可以是按组或按不同。
(这 2 个解决方案对我在 nhibernate 的进展会更好)
问候
编辑
Danyolviax,我尝试了你的解决方案
return (from adn in session.Query<Table>()
group adn by adn.Data into dataGroupe
select dataGroupe).ToList<string>();
它不起作用。 我担心我使用 Nhibernate 3.1(而不是 2.1)
有更正或替代解决方案吗?
编辑2
在第二个可行的解决方案中(^^)
我有一个具有一个属性的类的列表。 就我而言,我更喜欢有一个字符串或整数列表。 否则我应该为这种情况创建一个特定的类。
你知道一招吗。
感谢您的支持。
I need to do a simple "group by" with a nhibernate query.
My try were :
(from adn in session.Query<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请看这里:
Linq to NHibernate 和 Group By
这里有一些示例:
http://msdn.microsoft.com/en-us/vcsharp/aa336754
更新
尝试使用 3.1 .0.4000:
更新
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:
update