English 中文(简体)
如何组别 lin lin
原标题:How to groupBy in linq to sql?

我有这方面的数据。

id = 1<pk>
SDate = 12/12/2009
EDate = 12/12/2009
binding = a_1
userid = 14

id = 2<pk>
SDate = 12/12/2009
EDate = 12/12/2009
binding = a_1
userid = 14

我想通过具有约束力的方式把我的数据分类。 我并不肯定如何做到这一点。 我是否必须作出新的选择来这样做?

至今

 Db.Table.Where(u => u.UserId == userId && u.Binding == binding)
                .GroupBy(u => u.Binding)

因此,我要回到所有各栏。 我必须去做。

.select(group = new Table {....});
最佳回答

成员: By isn t as s GroupBy. 林克集团 回到了一张......Key(按情况属于你的群体),然后是一张可计算、可计算、可比较的“IE” ;并且是你重新分类的。 因此,如果你希望把每个具有约束力的条款与具有约束力的条款一并计算,那就是:

 var bindingsAndCounts = 
     Db.Table.Where(u => u.UserId == userId && u.Binding == binding)
                .GroupBy(u => u.Binding)
                .Select(g => new {g.Key, BindingCount = g.Count()});

这比与法国航天公司相比,是一座建筑的强大力量,因为你只能用“g”的表述来做任何事情。

如果你想通过每一组列举,你可以忽略选择:

foreach (var group in whateveryourgroupingExpressionWas) {
   Console.WriteLine(group.Key);
   foreach (var row in group) {
      Console.WriteLine("ID: " + row.Id + "Name " + row.Name ...);
   }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签