none
LINQ Basic Group by Having in LINQ RRS feed

  • Question

  • I am trying to express the following in LINQ and would appreciate help

    select * from arcs as r group by r.F1, r.F2, r.F3 having count(*) >= 1;

    I'm missing something here and it won't allow me to have 3 fields in the group by (F1, F2, F3).

    var duplicates = from r in arcs group r by r.F1, r.F2, r.F3 having count(*) >= 1 into g select g;

    Thanks

    Thursday, March 17, 2011 3:02 AM

Answers

  • Thanks,

    I figured it out.

                var duplicates =    from arc in arcs
                                    group arc by new { arc.F1, arc.F2, arc.F3, arc.F4 }
                                    into g
                                    where g.Count() >= 2
                                    orderby g.Key.F1, g.Key.F2
                                    select g;

    • Marked as answer by solardog Thursday, March 17, 2011 5:07 AM
    Thursday, March 17, 2011 4:59 AM

All replies

  • Thanks,

    I figured it out.

                var duplicates =    from arc in arcs
                                    group arc by new { arc.F1, arc.F2, arc.F3, arc.F4 }
                                    into g
                                    where g.Count() >= 2
                                    orderby g.Key.F1, g.Key.F2
                                    select g;

    • Marked as answer by solardog Thursday, March 17, 2011 5:07 AM
    Thursday, March 17, 2011 4:59 AM
  • Well done solardog, and thank your for sharing your solution to us!

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 17, 2011 8:44 AM
    Moderator