This object was constructed using a non-selfservicing constructor. Can't retrieve an IEntityField after that.

Posts   
 
    
Michel
User
Posts: 6
Joined: 22-Nov-2021
# Posted on: 22-Nov-2021 18:06:51   

Hello,

I have a problem with the LLBLGen Pro V2. version upgrade to 5.7. I regenerated in Adapter mode (as before) and I have an error on this method (the VB .Net code has not changed) :

.AddWithAnd(New FieldCompareRangePredicate( _
                                GroupFieldsA.FieldAAA, Nothing, list))

When I debug I see the following error:

'DirectCast(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of SD.LLBLGen.Pro.ORMSupportClasses.IPredicateExpressionElement) (DirectCast(filter.PredicateExpression, SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression)._predicates).Items(4)), SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpressionElement).Contents, SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareRangePredicate). Field' raised an exception of type 'System.InvalidOperationException'

"This object was constructed using a non-selfservicing constructor. Can't retrieve an IEntityField after that."

" to SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareRangePredicate.get_Field()"

I have searched everywhere but I could not find any solution to my problem. Can you please help me?

Thank you.

Michel
User
Posts: 6
Joined: 22-Nov-2021
# Posted on: 22-Nov-2021 18:12:43   

It's the same things with this code :

.AddWithAnd(New FieldCompareValuePredicate( _ GroupeFieldsA.FieldBBB, Nothing, _ ComparisonOperator.Equal, fieldConcept))

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 23-Nov-2021 09:39:11   

Remove the , Nothing in the constructor calls, as the SelfServicing variants don't require you to specify a persistenceinfo value, so they become:

.AddWithAnd(New FieldCompareRangePredicate( GroupFieldsA.FieldAAA, list))

Frans Bouma | Lead developer LLBLGen Pro
Michel
User
Posts: 6
Joined: 22-Nov-2021
# Posted on: 23-Nov-2021 10:05:13   

Hello Otis,

I just tried to remove the "Nothing" but I have this error now:

'Public Overloads Sub new(filed As IEntityFied, ParamArray values As Object())': Le paramètre de correspondance d'argument 'field' passe de 'EntityField2' à 'IEntityField'

I have the same problem on the other "FieldCompare and i tried to remove the "Nothing" on "FieldCompareValuePredicate" but i have have this error :

Impossible d'effectuer un cast d'un objet de type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' en type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'.

.Add(New FieldCompareValuePredicate( GroupFieldsA.FieldBBB, ComparisonOperator.Equal, idConcept))

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 23-Nov-2021 10:17:30   

Ah I misread your initial post. I thought you were using Selfservicing code and used an adapter constructor. You're using Adapter, and you generated code again, also using adapter, and now your code doesn't compile because you get the error. So leave the , Nothing as you had.

The error during debugging is ok. A debugger tries to read all properties, but some are for selfservicing and in the context of Adapter will give an error. This is not problematic. This is a backwards compatibility left-over. So you can safely ignore it. If you want to read the field of a predicate, use FieldCore, not Field: https://www.llblgen.com/Documentation/5.8/ReferenceManuals/LLBLGenProRTF/html/74164499.htm

You could replace

.Add(New FieldCompareValuePredicate(
                          GroupFieldsA.FieldBBB, Nothing,
                           ComparisonOperator.Equal, idConcept))

with

.Add(GroupFieldsA.FieldBBB.Equal(idConcept))

And add an Imports SD.LLBLGen.Pro.QuerySpec at the top of the file to get access to the extension methods. See: https://www.llblgen.com/Documentation/5.8/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/QuerySpec/gencode_queryspec_creatingpredicates.htm and https://www.llblgen.com/Documentation/5.8/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Filtering%20and%20Sorting/gencode_filteringpredicateclasses.htm

Frans Bouma | Lead developer LLBLGen Pro
Michel
User
Posts: 6
Joined: 22-Nov-2021
# Posted on: 23-Nov-2021 10:33:11   

No problem. If this is not a problem and this is a leftover backwards compatibility and I can safely ignore it I don't understand my next problem:

When I use the method adapt.FetchEntityCollection(listGroup, filter, prefetchPath)

I have no return in "listGroup" with V5.7 while in V2 I had information in return. I have no error or way to debug the "FetchEntityCollection" method. I thought that the error was in the "filter" with the error mentioned before.

Michel
User
Posts: 6
Joined: 22-Nov-2021
# Posted on: 23-Nov-2021 10:38:16   

And as a side note, I'd like to avoid touching the code too much. It's old code that we have and it's very large so we're trying to avoid rewriting how we build our queries.

Michel
User
Posts: 6
Joined: 22-Nov-2021
# Posted on: 23-Nov-2021 12:28:01   

Re Otis,

I think I found the problem but I don't understand why I had the error.

I had a deprecated method: If obj.TestCurrentFieldValueForNull( DalLocal.OfferFieldIndex.Id) Then

And I used a method that was recommended: If obj.Id Is Nothing Then

But in the "is Nothing" the condition is False and in the deprecated method the condition is True.

Do you have an explanation for this difference?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 23-Nov-2021 17:53:04   

When exactly was this piece of code run, could you please give a bit of a context? Was it run on a new entity, after a fetch, or after a save?