Tag Archives: GroupBy

CAML Query Example: Including GroupBy

Just to remember how to write these things.

                <FieldRef Name="myFieldName" />
                <Value Type="DateTime">
                  <Today OffsetDays="6"/>
                <FieldRef Name="myFieldName2"/>
                <Value Type="Choice">myFieldValue</Value>
            Collapse ="TRUE"
            GroupLimit ="100">
            <FieldRef Name="myFieldName">
            <FieldRef Name="MBLEventStart">

Get distinct object based on property in a collection.

This code is taken from the source further down. Just posted it here since it’s so useful.

What if want to distinct a list of Object on ONE or MORE Properties of the object?
Simple! You want to group them and pick a winner out of the group.

List<Person> distinctPeople = allPeople 
  .GroupBy(p => new {p.PersonId, p.FavoriteColor} ) 
  .Select(g => g.First()) 

Source here.