Attribute: [GroupBy]
Posted by Gerhard Stephan on March 7th, 2008
The [GroupBy] attribute can be used to group properties by there value. This property can only be used in projection classes.
/// <summary>
/// Groups the time entries by their project id
/// </summary>
public class TimeEntryGrouping
{
private DateTime minDate;
private string project;
/// <summary>
/// Gets or sets the min date.
/// </summary>
/// <value>The first date.</value>
[ProjectOntoProperty(typeof(TimeEntry), "StartDate")]
[Min]
public DateTime MinDate
{
get { return minDate; }
set { minDate = value; }
}
/// <summary>
/// Gets or sets the project.
/// </summary>
/// <value>The project.</value>
[ProjectOntoProperty(typeof(TimeEntry), "ProjectId")]
[GroupBy]
public string Project
{
get { return project; }
set { project = value; }
}
}
Select the grouping:
List<TimeEntryGrouping> result =
new List<TimeEntryGrouping>(
new ListAdapter<TimeEntryGrouping>(
mapper.FlatSelect(typeof(TimeEntryGrouping))));
