GUID variables are not supported in MySql databases

Posts   
 
    
cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 23-May-2014 09:49:09   

Hello,

I am trying to write simple Exists function. The code looks like this:

public bool Exists<TEntity>(Guid primaryKey) where TEntity : EntityBase2, new() { IEntity2 entity = new TEntity();

IPredicate filterPredicate = new FieldCompareValuePredicate(entity.PrimaryKeyFields[0], null, ComparisonOperator.Equal, primaryKey);

var count = (int?)Database.GetScalar(entity.PrimaryKeyFields[0], null, AggregateFunction.CountRow, filterPredicate);
return count.GetValueOrDefault() > 0;

}

When I execute it, I get an error that Guid is not supported in MySQL. I just want to get simple query like: select count(*) from table where column = 'value';

It works with GetDbCount.. however I do not like subquery for such a simple thing simple_smile Maybe you can suggest also other way to implement it?

Using LLBLGenPro 4.1-Final. Database: MySQL. Model first scenario.

regards Mantas

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 23-May-2014 17:12:17   

Please post the generated SQL query, and the exception stack trace.

Also why don't you just use adapter.FetchEntity()?

cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 26-May-2014 08:20:28   

Its not able to generate query because of this exception simple_smile

I am not using FetchEntity for performance reasons. However, probably it would be possible to use method overload with include/exclude field list.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-May-2014 17:40:41   

Could you post the full stacktrace?

Frans Bouma | Lead developer LLBLGen Pro
cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 27-May-2014 10:56:36   

System.NotSupportedException : GUID variables are not supported in MySql databases.
   at SD.LLBLGen.Pro.DQE.MySql.MySqlSpecificCreator.DetermineDbTypeNameForValue(Object value, ref Object realValueToUse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\MySqlDQE\MySqlSpecificCreator.cs: line 134
   at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameter(ParameterDirection direction, Object valueToSet) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DbSpecificCreatorBase.cs: line 162
   at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Boolean inHavingClause) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\QueryApiElements\FieldCompareValuePredicate.cs: line 292
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\QueryApiElements\PredicateExpression.cs: line 226
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.AppendWhereClause(IPredicate filter, QueryFragments destination, IQuery query) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DynamicQueryEngineBase.cs: line 1581
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IRetrievalQuery query, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DynamicQueryEngineBase.cs: line 1267
   at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\DynamicQueryEngineBase.cs: line 1128
   at SD.LLBLGen.Pro.DQE.MySql.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse, IPredicate selectFilter, Int32 rowsToSkip, Int32 rowsToTake, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\MySqlDQE\DynamicQueryEngine.cs: line 284
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ(QueryParameters parameters) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs: line 4155
   at Visma.School.DataAccess.Repositories.Context.MySqlDataAccessAdapter.CreateSelectDQ(QueryParameters parameters) in MySqlDataAccessAdapter.cs: line 34
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetScalar(IEntityFields2 fields, IPredicate filter, IGroupByCollection groupByClause, IRelationCollection relations) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs: line 373
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetScalar(IEntityField2 field, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IGroupByCollection groupByClause, IRelationCollection relations) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs: line 296
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetScalar(IEntityField2 field, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs: line 244
   at Visma.School.DataAccess.Repositories.EntityRepository`1.Exists(Guid primaryKey) in EntityRepository.cs: line 69
   at Visma.School.DataAccess.Repositories.EntityRepository`1.Exists(Guid primaryKey) in EntityRepository.cs: line 50

At Line: 69: var count = (int?)Database.GetScalar(entity.PrimaryKeyFields[0], null, AggregateFunction.CountRow, filterPredicate); from function in first post.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-May-2014 15:17:56   

The problem is caused by the Guid value itself. The query engine has no idea how to convert that to a value which is usable in the DB. So if you map guid fields to a byte[] field you should pre-convert the guid to a byte array and pass that as value in the predicate. The engine doesn't use the type converter set on the field to convert the guid value. I admit, this is possible, but only in a subset of cases: expressions compared to a field for example are not possible to re-use the typeconverter. Is it a problem to convert the guid before assigning it to the predicate?

Frans Bouma | Lead developer LLBLGen Pro
cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 29-May-2014 10:19:18   

It seems that passing byte array value solved the problem. Thank you very much.