Q:

EntityDataSource GROUPBY problem

can anyone explain why this code is causing an error?
<asp:EntityDataSource ID="EntityDataSource1" runat="server" 
    ContextTypeName="bookingModel.bookingEntities" 
    EntitySetName="t_sessionSet" 
    Select="it.[t_session_id], it.[t_session_datetime], it.[t_session_location], it.[t_session_active], it.[t_session_notes], it.[t_session_trainer]"
    GroupBy="it.[t_session_datetime]" >
</asp:EntityDataSource>

The error I get is: "The identifier 'it' is not valid because it is not contained either in an aggregate function or in the GROUP BY clause."

A:

In the Select clause you cannot use properties which you don't use in the GroupBy clause. You either need to omit all other properties except for t_session_datetime from the Select clause or add them to the GroupBy clause or apply aggregate function - for instance Count, Min, Max, Sum, etc. to them. Your Select clause could then look like:
Select="Min(it.[t_session_id]) AS MinId,
    it.[t_session_datetime],
    Min(it.[t_session_location]) AS Location,
    Min(it.[t_session_active]) AS Active,
    Min(it.[t_session_notes]) AS Notes,
    Min(it.[t_session_trainer]) AS Trainer"

I am not sure if this will work for Active if that is a boolean property. You can find a list of aggregate functions which are available in Entity SQL here.

