Linq query problem "Booleans are not supported in MySql databases."

Posts   
 
    
Liero
User
Posts: 40
Joined: 18-Sep-2009
# Posted on: 25-May-2010 16:06:16   

I have my own class Conference.

following query:

 var errorQuery = from s in new LinqMetaData().Sessions
                     select new Conference { Id = s.Id, Name = s.Title, IsPredefined = true };

results in exception when enumerating:

{"Booleans are not supported in MySql databases."}

source: SD.LLBLGen.Pro.DQE.MySql.NET20

stackTrace:

at SD.LLBLGen.Pro.DQE.MySql.MySqlSpecificCreator.CreateParameter(String name, ParameterDirection direction, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.CreateParameterFragments(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DbFunctionCall.SD.LLBLGen.Pro.ORMSupportClasses.IExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.ConvertFieldToRawName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) at SD.LLBLGen.Pro.DQE.MySql.MySqlSpecificCreator.CreateFieldName(IEntityFieldCore fieldCore, IFieldPersistenceInfo persistenceInfo, String fieldName, String objectAlias, Int32& uniqueMarker, Boolean applyAggregateFunction) at SD.LLBLGen.Pro.DQE.MySql.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) at SD.LLBLGen.Pro.DQE.MySql.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFields selectList, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, IEntityFields fields, IPredicateExpression filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteValueListProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.First[TSource](IQueryable1 source)

hovever this works fine:


          var test = (from s in new LinqMetaData().Sessions select s).ToList()
                                  .Select(s => new Conference { Id = s.Id, Name = s.Title, IsPredefined = true });

using LLBL GEN PRO v2.6, SelfServicing, .NET 3.5 SP1, DevArt dotConnect dbProvider v5.70.124.0.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 25-May-2010 23:01:34   

I'll get the dev team to take a look for you.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39887
Joined: 17-Aug-2003
# Posted on: 26-May-2010 10:28:50   

The exception occurs because boolean fields (bit types) aren't supported by llblgen pro on mysql. The reason is that the used ado.net provider converts them to int64 values. So although mysql has a 'bit' type, they're not converted to boolean values on the .NET level.

You now might wonder why this is a problem, as the value is in the projection which is executed in-memory. The reason is that the value is sent to the db as a value to occur in the projection. This might sound odd, but the projection of classes can be very complex and the linq provider has to determine which parts are values / fields and which parts are code. The 'true' value is seen as a value so it has to be sent to the db. As that happens in a parameter, it crashes, as a boolean value can't be send.

To work around this, set the IsPredefined property to true in the ctor of Conference. This way you don't have specify it in the projection.

The reason why the ToList() workaround works too is because the '.ToList()' call enumerates over the query, so the ToList() call creates a list of entity instances in-memory on which the .Select runs. This gives lower performance of course as you first have to materialize a list of entities.

Frans Bouma | Lead developer LLBLGen Pro