Grouping by multiple columns using a BindingSource does not work

entity-framework-6 vb.net

Question

In entity Frameowrk 6 , i need to group by multiple columns and after find how many groups have more than 1 item.

This is my code :

context.obj1s.load()

Bindingsource1.Datasource=context.obj1s.Local.Tolist

Dim q As Integer = Bindingsource1.Datasource.
                                  GroupBy(Function(x) New With {key.name=x.name, key.price=x.Price,key.lg= x.lg}).
                                  Where(Function(t3) t3.Count > 1).
                                  Count

I run this query against this table :

Name..........Price.......lg....Status

A.....................2...........5......nm1

A.....................2...........5......nm2

A.....................2...........5.......nm3

B.....................7...........4........tr5

I'm expecting that q=1 , but q=0.

What i'm doing wrong ?

1
0
12/7/2018 1:30:41 AM

Accepted Answer

THIS IS WORKING :

Dim q As Integer = DirectCast(Bindingsource1.Datasource,Ienumerable(of obj1)).
               GroupBy(Function(x) 
               New With {key.name=x.name, key.price=x.Price,key.lg= x.lg}).
               Where(Function(t3) t3.Count > 1).Count

Thank you !

0
12/7/2018 2:16:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow