我是这样从数据库中获取数据的。
Dim query = From t1 In TBL1 _ Join t2 In TBL2 On t1.ID Equals t2.ID _ Join t3 In TBL3 On t1.ID Equals t3.ID _ Group Join t4 In t1 _ On t1.ID Equals t4.ID _ Into t4_Grp = Group _ Select t1, t2, t3, t4_Grp
当用户执行搜索时,我可以像这样过滤查询结果。
query = query.Where(Function(o) o.t1.ID = lngID)
一切都很好,直到我想要对t4_Grp进行lambda处理。我不知道如何对t4_Grp使用lambda表达式?
如何在Linq to Sql结果中使用Lambda对数据进行分组?
原标题:
问题回答
过去我用过这个来进行一些强制分组。
private void ProducePivotAnalytic <T, K>(IEnumerable<T> colletion, Func<T, K> pivot)
{
var grouped =
from n in colletion
group n by pivot(n) into g
select new { theKey = g.Key, theValue = g };
// do some stuff with your grouped collection.
}
ProducePivotAnalytic<List<DateTime>, DayOfWeek>(
myDates,
(x) => (x.DayOfWeek) );
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding