Link to home
Start Free TrialLog in
Avatar of dchau12
dchau12

asked on

LINQ question

I have a List object in c#.  I want to group by three fields in that list and test for a duplicate record.  In SQL, it would look like this:

select field1, field2, field3
from Table1
group by field1, field2, field3
having count(*) > 1

Is this possible to do in LINQ?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My example is VERY crude--don't read into the variable names, I merely wanted to demonstrate syntax.
Avatar of dchau12
dchau12

ASKER

I got it working, and I can see the value that it found, but how do I then mine that value out of "data"?  intelisense only brings up more predicate methods.
Avatar of dchau12

ASKER

I can see everything in data2's method "Results View", but how do i access the method?

     var data2 = from f in myList
                        group f by new { f.TrpCarrierId, f.Mode, f.CarrierStatusCode }
                        into myGroup
                        where myGroup.Count() > 1
                        select new
                        {
                          myGroup.Key.TrpCarrierId,
                          myGroup.Key.Mode,
                          myGroup.Key.CarrierStatusCode,
                          MyCount = myGroup.Count()
                        };
I believe it would be something like:

foreach (var d in data2)
{
     string.Concat(d.TrpCarrierId, d.Mode);  // etc.
}
Avatar of dchau12

ASKER

You rock!
:)

Glad to help.