asp.net - LINQ grouping with count issue -


i'm having trouble trying group linq query count correctly. example i'm trying query datatable following data:

pc ec cc

abc xxx us

abc xxx ca

abc xxx uk

def yyy us

def yyy ca

def yyy uk

def zzz us

def zzz ca

def zzz uk

hij aaa us

hij aaa ca

hij aaa uk

i want use count function show number of different values of ec each value of pc, removing values in cc. in other words result above dataset should be:

pc count ec

abc 1

def 2

hij 1

i've tried several different ways of getting result keep hitting wall. last attempt looked this:

 dim test = r in ( _                         s in base _                         group s.base_pc, _                                  s.base_ec _                         g = group) _                         group r key = new {r.base_pc} _                         group _                         select key.base_pc, group.count 

any ideas i'm going wrong? thanks!

here method syntax since it's query syntax:

dim counts = base.asenumerable().     groupby(function(r) r.field(of string)("pc")).     select(function(g) new {                .pc = g.key,                .countec = g.select(function(r) r.field(of string)("ec")).                             distinct().                             count()            })  each x in counts     console.writeline("pc={0} count of distinct ec's={1}", x.pc, x.countec) next 

first need group "pc" column, select anonymous type group's key , count of distinct values of "ec" column.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -