Dear all,
I was attempting to grab a collection of an object to place into a new reporting object. When I do this with a group by clause I get an error explaining that all the columns of the class are not contained within the group by clause.
Here is the constructor in the PlanningProjectSummary class:
Code:
public ProjectFundingSummary(PlanningProject pp)
{
_planningproject = pp;
}
My query is this:
Code:
Select new ProjectFundingSummary (pf.PlanningProject)
from ProjectFunding as pf where pf.PlanningProject.PlanningProjectId = :projectPlanId
group by pf.PlanningProject
I could take out the group by clause and it will work. Unfortunately what I really want to do is groupby this object and add an aggregate calculating the TotalAmount of the group. This wasn't working, I kept getting an invalid constructor error, so I rolled back to just passing the object over in a groupby and I started to get the problem.
What I wanted to get back to is this:
Code:
Select new ProjectFundingSummary (pf.PlanningProject, sum(pf.FundingAmount))
from ProjectFunding as pf where pf.PlanningProject.PlanningProjectId = :projectPlanId
group by pf.PlanningProject
Hibernate version: 1.0.2
Mapping documents:Full stack trace of any exception that occurs:Code:
SqlException (0x80131904): Column 'planningpr1_.PlanningProjectId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.PlanningProjectStatusId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.LocationId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsNewLandRequired' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsElectionCommitment' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsNewBuild' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.DateUpdated' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.DateCreated' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.CapitalWorksProject' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.CostCentre' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.FacilityMgmtBlock' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.PlanningProjectTypeId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.MigrationKey' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.ProjectCost' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsRowDeleted' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.BuildingPriceIndex' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.BusinessCase' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsBuildingInProgress' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.Comments' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.PlanningProjectDescId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.Priority' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsMinorWork' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857242
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734854
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +9
NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd) +73
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session) +175
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +243
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +65
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) +222
NHibernate.Hql.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters) +64
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) +200
Name and version of the database you are using: SQL 2000
Code:
Any idea on this, am I attempting to do something I shouldn't be.
Cheers,
Jason