Linq to Nhibernate 3.1 Group By(或不同)

发布于 2024-11-10 08:51:16 字数 929 浏览 7 评论 0原文

我需要用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷情妓 2024-11-17 08:51:16

请看这里:

Linq to NHibernate 和 Group By

这里有一些示例:

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

更新

尝试使用 3.1 .0.4000:

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

更新

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

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>();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文