Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var query =
- from foo in fooStuff.AsEnumerable()
- group foo by foo.Field<Int64>("FooID") into g
- select new
- {
- FooID = g.Key,
- FooTier = g.Min(foo => foo.Field<int>("Tier"))
- };
- var query =
- from foo in fooStuff
- group foo by foo.FooID into g
- select new
- {
- FooID = g.Key,
- FooTier = g.Min(foo => foo.Tier)
- };
- var fooList = fooStuff.AsEnumerable().ToList();
- var list2 =
- (from foo in fooStuff.AsEnumerable()
- select new {
- FooID = foo.Field<Int64>("FooID")
- Tier = foo.Field<int>("Tier")
- }).ToList();
- var query =
- from foo in list2
- group foo by foo.FooID into g
- select new
- {
- FooID = g.Key,
- FooTier = g.Min(foo => foo.Tier)
- };
- var results = query.ToList();
- public static Dictionary<TKey, List<TSrc>> TestGroupBy<TSrc, TKey>
- (this IEnumerable<TSrc> src, Func<TSrc,TKey> groupFunc)
- {
- var dict= new Dictionary<TKey, List<TSrc>>();
- foreach (TSrc s in src)
- {
- TKey key = groupFunc(s);
- List<TSrc> list ;
- if (!dict.TryGetValue(key, out list))
- {
- list = new List<TSrc>();
- dict.Add(key, list);
- }
- list.Add(s);
- }
- return dict;
- }
- var results = list2.TestGroupBy(r=>r.FooID)
- .Select(r=> new { FooID = r.Key, FooTier = r.Value.Min(r1=>r1.Tier)} );
Add Comment
Please, Sign In to add comment