This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
This exception is being thrown when my LINQ code executes: "An expression of non-boolean type specified in a context where a condition is expected, near ')'." Here is the code:
var result = (from p in uow.Properties where p.MarketId == marketID && (p.PropertyCity.Contains(city) || city.Equals("")) select p).Take(300).ToList(); If I comment out the line that begins with && it executes fine.
Thanks,
Damon
|
|
|
Could you provide us with the inner part of the stack trace please? Also, am I right in thinking that city is a local variable external to the query? If so you can lift the '|| city.Equals("")' bit outside the query which might help: var query = city.Equals("") ? We used to have a couple of bugs around constant (for the query) boolean values, though we thought we had addressed all of those. Finally, we have made some fixes to our Contains handling since RTM. Are you on a recent nightly build? If not could you upgrade and see if that resolves the problem? |
|
|
I installed nightly build 5/6/2010 and tried this again. It still throws the same exception. In trying to simplify this, I ran the query through LINKPad using the Lightspeed driver. Here is the simplified query: from p in Properties Here is the resulting SQL, you can see why the exception is being thrown based on the SQL that is generated:
SELECT
Here is the inner stack trace:
System.Data.SqlClient.SqlException was unhandled by user code Message=An expression of non-boolean type specified in a context where a condition is expected, near ')'. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=15 LineNumber=98 Number=4145 Procedure="" Server=76.12.115.140 State=1 StackTrace: 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 ...() at ..(IUnitOfWork , IDbCommand , ) at ..(IUnitOfWork , IDbCommand ) at ...ctor(IUnitOfWork , IEnumerable`1 ) at Mindscape.LightSpeed.Data.DataProviderAdapter.(IUnitOfWork , IEnumerable`1 , ProviderOptions ) at ..(TypeModel , Query , IList ) at ..(UnitOfWorkBase , TypeModel , Query , IList ) at ..(Query , TypeModel , IList ) at ..(Query , IList ) at Mindscape.LightSpeed.UnitOfWork.Find(Query query, IList results) at Mindscape.LightSpeed.UnitOfWorkBase.Find(Query query) at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteImmediate(IUnitOfWork unitOfWork, Type returnType) at Mindscape.LightSpeed.Linq.LinqQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQuery`1.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at ui_ssl_evaluation_home.GridEvaluations_NeedDataSource(Object source, GridNeedDataSourceEventArgs e) in c:\Data\Work\Projects\Quest\Src2\WebSite\ui\ssl\evaluation\home.aspx.cs:line 51 at Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e) at Telerik.Web.UI.RadGrid.ObtainDataSource(GridRebindReason rebindReason, Boolean IsBoundUsingDataSourceId) at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) at Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException: |
|
|
I installed nightly build 5/6/2010 and tried this again. It still throws the same exception. In trying to simplify this, I ran the query through LINKPad using the Lightspeed driver. Here is the simplified query: from p in Properties Here is the resulting SQL, you can see why the exception is being thrown based on the SQL that is generated:
SELECT
Here is the inner stack trace:
System.Data.SqlClient.SqlException was unhandled by user code Message=An expression of non-boolean type specified in a context where a condition is expected, near ')'. Source=.Net SqlClient Data Provider ErrorCode=-2146232060 Class=15 LineNumber=98 Number=4145 Procedure="" Server=76.12.115.140 State=1 StackTrace: 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 ...() at ..(IUnitOfWork , IDbCommand , ) at ..(IUnitOfWork , IDbCommand ) at ...ctor(IUnitOfWork , IEnumerable`1 ) at Mindscape.LightSpeed.Data.DataProviderAdapter.(IUnitOfWork , IEnumerable`1 , ProviderOptions ) at ..(TypeModel , Query , IList ) at ..(UnitOfWorkBase , TypeModel , Query , IList ) at ..(Query , TypeModel , IList ) at ..(Query , IList ) at Mindscape.LightSpeed.UnitOfWork.Find(Query query, IList results) at Mindscape.LightSpeed.UnitOfWorkBase.Find(Query query) at Mindscape.LightSpeed.Linq.Plan.SingleQueryPlan.ExecuteImmediate(IUnitOfWork unitOfWork, Type returnType) at Mindscape.LightSpeed.Linq.LinqQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQuery`1.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at ui_ssl_evaluation_home.GridEvaluations_NeedDataSource(Object source, GridNeedDataSourceEventArgs e) in c:\Data\Work\Projects\Quest\Src2\WebSite\ui\ssl\evaluation\home.aspx.cs:line 51 at Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e) at Telerik.Web.UI.RadGrid.ObtainDataSource(GridRebindReason rebindReason, Boolean IsBoundUsingDataSourceId) at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) at Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:
|
|
|
I installed nightly build 5/6/2010 and tried this again. It still throws the same exception. In trying to simplify this, I ran the query through LINKPad using the Lightspeed driver. Here is the simplified query: from p in Properties Here is the resulting SQL, you can see why the exception is being thrown based on the SQL that is generated: SELECT
|
|
|
It looks like we had not handled the case where the boolean constant was in a nested expression. I have committed a candidate fix for this and it will be in the 8 May nightly build. Please let us know if you still see the problem after this. |
|
|
I've installed the May 8 nightly build and the sample linq query in the above posts now works. However my code isn't working, I'm still getting the same exception. here must be another case of boolean constants that isn't being handled correctly. Here is the code I'm executing:
var evalRslt = (from e in Evaluations where (e.UserId == userID) && (e.IsVisible || showHidden == true) && (e.LastModified >= startDate) && (e.LastModified <= stopDate) && (e.IsDeleted == false || e.IsDeleted == null) && (string.IsNullOrEmpty(search) || e.EvaluationStreetAddress.Contains(search) || e.EvaluationStreetAddress.Contains(search) || e.EvaluationSubdivision.Contains(search) || e.EvaluationMls == evaluationMls || e.EvaluationZip.Contains(search)) orderby e.LastModified descending select e).ToList();
If I take out the "string.IsNullOrEmpty(search)" it executes fine. With it, the exception is thrown. Search is a string, if that helps. Thanks for checking into this. Damon |
|
|
I've committed a fix for the updated code sample, and it will be in the 11 May nightly build. Please let us know if you still see problems. |
|
|
The May 11 nightly build works perfectly. Thanks! |
|