Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> What kind of query is that!
 

Pages: 1
LLBLGen Pro Runtime Framework
What kind of query is that!
Page:1/1 

  Print all messages in this thread  
Poster Message
simmotech
User



Location:

Joined on:
01-Feb-2006 15:43:00
Posted:
1006 posts
# Posted on: 25-Apr-2019 15:24:42. Goto attachments  
I've just changed a column from being nvarchar(32) to binary(20)

And this query now completely fails:-
Code:
                    var existingImage = adapter.FetchFirst(new QueryFactory().Image
                        .Where(ImageFields.Hash == coverImage.Hash)
                        .Where(ImageFields.Data.Length().Equal(bytes.Length)));


This is the Exception
Code:
SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException
HResult=0x80131600
Message=An exception was caught during the execution of a retrieval query: Failed to convert parameter value from a Byte to a Byte[].. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
Source=SD.LLBLGen.Pro.ORMSupportClasses
StackTrace:
at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityMaterializerBase.Materialize(Func`4 valueReadErrorHandler, String& failureErrorText)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery)
at SmartLibrarian.DAL.DatabaseSpecific.DataAccessAdapter.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) in F:\src\SmartLibrarian\SmartLibrarian.DAL\Custom\DataAccessAdapter.cs:line 586

Inner Exception 1:
InvalidCastException: Failed to convert parameter value from a Byte to a Byte[].

Inner Exception 2:
InvalidCastException: Invalid cast from 'System.Byte' to 'System.Byte[]'.


I'll attach a screenshot of the query is trying to generate but the gist of it is that LLBLGen has tried to create a Parameter for each byte!

But the query should look something like this for SQL Server
Code:
SELECT * FROM Image WHERE Hash=0xC33608676DA2787A319312A6CE0B81A3D4CFFC82


  Top
simmotech
User



Location:

Joined on:
01-Feb-2006 15:43:00
Posted:
1006 posts
# Posted on: 25-Apr-2019 15:30:44.  
Panic over!

This predicate works
Code:
.Where(ImageFields.Hash.Equal(coverImage.Hash))


But why aren't both filters equivalent?


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 25-Apr-2019 15:35:59.  
This is a problem with the '==' operator overload. It's defined on EntityField2 and it overloads the '==' operator for various operands: IExpression, object, EntityField2 and... IList. Array implements IList and this matches with this overload, so it will produce a FieldCompareRange predicate as that's what that overload does. In hindsight these overloads for these operators shouldn't have happened, but alas, what's done is done.

To fix this, use .Where(ImageFields.Hash.Equal(coverImage.Hash)). This will produce a FieldCompareValuePredicate as the method to produce an IN() clause is .In(IEnumerable), not .Equal.
It's recommended to use the QuerySpec operators btw, and leave the operator overloads for what they are: a relic

(edit) you just beat me to it Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.