vb.net - Casting Anonymous Type LINQ Using TryCast Returns Nothing -


i want query return list (of service) want use new list further filter.

when run query exectutes correctly

dim duplicateservice = svggrpcontainer.groupby(function(x) x.servicegroup).where(function(x) x.count > 1).select(function(x) x) 

i attempting cast in oder use , create query

    dim duplicatepak = duplicateservicegroups.groupby(function(x) x.name).where(function(x) x.count > 1).select(function(x) x) 

when cast first query returns nothing

 dim duplicateservice list(of servicegroup) = trycast(svggrpcontainer.groupby(function(x) x.servicegroup).where(function(x) x.count > 1).select(function(x) x), list(of servicegroup)) 

tolist throws grouping exception tried that.

how cast query can further filter data in subsequent queries? or use 1 query , group both group , name?

here's .net fiddle working solution (forgive c#).

c#: https://dotnetfiddle.net/puqnss vb.net: https://dotnetfiddle.net/aixeib

you need use anonymous object group multiple fields , selectmany flatten list.

the main idea is

    dim duplicates list(of thing) =          things.             groupby(function(thing) new {key .name = thing.name, key .servicegroup = thing.servicegroup }).             where(function(group) group.count() > 1).             selectmany(function(group) group.tolist).             tolist() 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -