My criteria query is throwing a SqlException "Invalid Column Name". Here's the code that creates the criteria:
Code:
DetachedCriteria criteria = DetachedCriteria.For(typeof(OrderRequest));
criteria.Add(Expression.In("Status", (IList)Statuses));
criteria.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("Id"), "Id")
.Add(Projections.Property("Status"), "Status"));
And here is the resulting SQL:
Code:
SELECT this_.OrderRequestID as y0_, this_.StatusCode as y1_ FROM OrderRequest this_ WHERE y1_ in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
SQL Server is complaining that there is no column named "y1_" when it evaluates the WHERE clause. True there is not. If I manually change "y1_" to "StatusCode" SQL Server likes it fine. If I remove the Projection for StatusCode, it works fine because NHibernate does not try to use the alias in the WHERE clause.
I am using 1.2 RC2
This seems like a bug in NHibernate. Any ideas?
Here's the stack trace:
Code:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)
at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List[T]()
at Maestro.Persistence.EntityDataGateway.GetCollection[T](ISearchCriteria searchCriteria) in C:\wush\Maestro\src\Maestro.Core\Maestro.Persistence\EntityDataGateway.cs:line 684
at Maestro.Domain.OrderRequestRepository.GetOrderRequestDtos(OrderRequestCriteria criteria)
at Maestro.OrderProcessMonitor.Controllers.OrderRequestsController.List()