{Collection of entities of type 'ApplicationSettingEntity'. Current number of elements: 0}

Posts   
 
    
Posts: 7
Joined: 31-Aug-2022
# Posted on: 31-Aug-2022 08:56:34   

I'm receiving the following error when trying to execute a FetchAll on my defined entity 'ApplicationSettingEntity'. The entity definitely exists in the EntityClasses folder so I'm unsure where to go at this point.

The FetchAll code is as follows:

public virtual EntityCollection<TEntityType> FetchAll(IRelationPredicateBucket aPredicate, int maxNumberOfItemsToReturn, SortExpression aSortExpression, IPrefetchPath2 aPrefetchPath, ExcludeIncludeFieldsList excludedFields)
{
  EntityCollection<TEntityType> result = null;

  try
  {
    aPredicate = AddLogicalDeletionPredicate(aPredicate);

    result = new EntityCollection<TEntityType>();
    this.Adapter.FetchEntityCollection(result, aPredicate, maxNumberOfItemsToReturn, aSortExpression, aPrefetchPath, excludedFields);
  }
  catch (Exception ex)
  {
    throw TranslateException(ex);
  }

  return result;
}

The application is producing this error when it hits the result = new EntityCollection<TEntityType>(); line of code.

Could anybody assist me with this issue?

Regards,

Michael Hennessey
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 31-Aug-2022 09:11:39   

what is the exact error you're getting, and is that at compile time/runtime? Also please post version information, see: https://www.llblgen.com/tinyforum/Thread/7717/1

Frans Bouma | Lead developer LLBLGen Pro
Posts: 7
Joined: 31-Aug-2022
# Posted on: 31-Aug-2022 09:28:02   

Hi Otis,

This is using llblgen v5.9 and the SD.LLBLGen.Pro.ORMSupportClasses v4.0.30319 library. The issue is occurring at runtime.

When the 'FetchEntityCollection' function tries to execute, the following error occurs:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=SD.LLBLGen.Pro.ORMSupportClasses
  StackTrace:
   at SD.LLBLGen.Pro.ORMSupportClasses.Adapter.QueryCreationManager.PrepareParametersForCollectionFetch(QueryParameters parameters)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchEntityCollectionInternal(QueryParameters parameters)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchEntityCollection(QueryParameters parameters)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.<>c__DisplayClass10_0.<FetchEntityCollection>b__0()
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields)
   at Mrwa.Vls.Services.Framework.BaseEntityService`1.FetchAll(IRelationPredicateBucket aPredicate, Int32 maxNumberOfItemsToReturn, SortExpression aSortExpression, IPrefetchPath2 aPrefetchPath, ExcludeIncludeFieldsList excludedFields) in E:\Users\c9646-adm\Source\Repos\RAVS\Services\ServicesFramework\BaseEntityService.cs:line 147

I believe this is because the 'result' variable is being set to '{Collection of entities of type 'ApplicationSettingEntity'. Current number of elements: 0}' after trying to create the Entity collection.

Regards,

Michael Hennessey
Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 31-Aug-2022 19:55:34   

SD.LLBLGen.Pro.ORMSupportClasses v4.0.30319

That's the .NET version, not the library file version.

So, it's a runtime exception of adapter.FetchEntityCollection(), not on the initialization of the collection as said earlier.

Did you validate the entity type used in the collection? Does this Entity have fields defined?

Posts: 7
Joined: 31-Aug-2022
# Posted on: 01-Sep-2022 03:27:27   

Apologies. The File version is v5.9.2.0

It is also probably worth noting that the project I am working on was originally an LLBLGen v2.5 project (that was working correctly) that has been converted using the v2xToV5 Migration template. The entity does have fields defined, the result of calling ModelInfoProviderSingleton.GetInstance().GetEntityFields(entity) on the ApplicationSettingEntity returns the correct count of the fields defined (10) - however it only seems to be mapping to the primary key and the rest of the fields are coming through as null.

I have validated the project in LLBLGen before generating the code, however I'm unsure what you mean by validating the entity type.

Thanks for the prompt response.

Regards,

Michael Hennessey
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 01-Sep-2022 09:28:31   

The error appears to happen on the FetchEntityCollection call, as seen in the stacktrace.

Code looks normal, and should work so it's something else, but what is unclear. In case you have Resharper or use JB Rider, you can step into the FetchEntityCollection and debug to the SD.LLBLGen.Pro.ORMSupportClasses.Adapter.QueryCreationManager.PrepareParametersForCollectionFetch(QueryParameters parameters) method and see where exactly the null reference exception occurs. that way we know more about why this happens and what is perhaps wrong. (I don't know if Visual Studio 2022 offers this feature btw).

Assuming the code is generated with 5.9 as well?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 7
Joined: 31-Aug-2022
# Posted on: 07-Sep-2022 09:39:09   

Hi Otis,

You're correct, the code has been generated using v5.9.

After setting up JB Rider I've stepped into the code. I'm unfamiliar with the IDE and how its supposed to behave when stepping through .DLLs but when trying to step over the following code statement within the PrepareParametersForCollectionFetch function it will step me out - I'm assuming this means the code statement is failing.

DummyInstancesProviderSingleton.GetInstance().GetEntityInstanceDummyForEntityFactoryType(parameters.CollectionToFetch.EntityFactoryToUse);

it is worth noting that parameters.CollectionToFetch.EntityFactoryToUse contains the correctly named Entity Factory "ApplicationSettingEntityFactory".

Stepping into the above function, the function looks like it is failing on:

instance = factory.Create();

Appreciate the assistance with this matter.

Regards,

Michael Hennessey
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 07-Sep-2022 10:21:52   

Hmm. The factory can't be null otherwise it wouldn't be on that line, so if you step into that Create() method, did that work or does it step over? Is 'factory' null on that factory.Create() line? (I doubt it, the null check is above it).

Create will go into EntityFactoryCore2.Create() which will call Create(fields) by passing null, which will call CreateImpl() which will end up in the generated factory class for that entity, so the ApplicationSettingEntityFactory (this is in the file FactoryClasses\EntityFactories.cs). This will simply do a new ApplicationSettingEntity(fields), which will end up in the constructor of the entity.

What I think what might be off is that you have leftover code of 2.6 perhaps?

If you set a breakpoint in the constructor of ApplicationSettingEntity which accepts fields (which will be null but that's fine), you should break there when you run the method that fails with the exception.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 7
Joined: 31-Aug-2022
# Posted on: 12-Oct-2022 03:31:21   

Hi Otis,

Thanks a lot for the help regarding this.

You're advice in using Jetbrains to step into the library allowed me to see that I was calling the wrong constructor for the entity which resulted in the fields not being created.

Once again, I appreciate the help.

Regards,

Michael Hennessey

Michael Hennessey