adapter.FetchTypedList error

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 08-Dec-2006 21:49:04   

I am using the 2006/12/6 LLBLGen, Adapter model

I have a TypedList defined in an LLBL project, This typed list uses fields from two related entities. When I try to execute the followin fetch command


Private m_employeeRegionsTypedList As EmployeeRegionsTypedList
m_employeeRegionsTypedList = New EmployeeRegionsTypedList()
Using adapter As IDataAccessAdapter = DataAdapterFactory.Create()
    adapter.FetchTypedList( _
        m_employeeRegionsTypedList.GetFieldsInfo(), _
        m_employeeRegionsTypedList, _
        criteria.Bucket, criteria.NumberOfRecordsToReturn, _
        criteria.Sorter, criteria.AllowDuplicates)
End Using

I get a system.ArgumentException

Message:

"An entity name has been specified which isn't in an inheritance hierarchy. This is often caused by a typedlist fetch where no relations have been specified so LLBLGen Pro will assume all fields belong to a subtype in a hierarchy. Parameter name: entityNames"

Stack Trace

" at SD.LLBLGen.Pro.ORMSupportClasses.InheritanceInfoProviderBase.GetHierarchyRelations(List`1 entityNames) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateQueryFromElements(IEntityFields2 fieldCollectionToFetch, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize, IFieldPersistenceInfo[]& persistenceInfo, IRetrievalQuery& selectQuery) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates) at NW.Sales.BL.ReadOnlyListClasses.EmployeeRegionsReadOnlyList.DataPortal_Fetch(Criteria criteria) in D:\Projects\JCL2.3\NWvb\NW.Sales.BL\ReadOnlyListClasses\Generator\EmployeeRegionsReadOnlyList.Generator.vb:line 200"

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 08-Dec-2006 22:37:34   

Could you describe the typedlist with the entities (also their inheritance hierarchy)? In v2.0 (will be solved in v2.1 with an architectural change) there's currently a rare issue with inheritance and typedlists.

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 09-Dec-2006 09:42:49   

This is actually for the SQL Northwind database.

The entities selected for this typedList are:

Employees EmployeeTerritories Region Territories

Fields mapped on entity fields

Object Name Field Name


Emplyees EmployeeId Emplyees LastName Emplyees FirstName Emplyees Title Emplyees City Emplyees Country

Territories TerritoryDescription

Region RegionDescription

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Dec-2006 10:11:45   

Ok, the exception you're seeing is thrown by code which was added on November 27th with this reason:

A guard clause has been added to an internal method of the InheritanceInfoProvider class to make it report less cryptic errors when a typedlist fetch was executed without any relations specified while there were fields in the typedlist from more than one entity.

Before that, you just got a hard key not found crash in the inheritance info provider.

So you pass in a set of fields without specifying relations, which makes the code think you pass in fields from 1 entity which are the fields of a subtype (as there are fields from multiple entities).

Please check the typedlist call code to see if you pass the typedlist relations as well, it might be you don't pass the bucket from GetRelationInfo to the call routine. (Checking your code in the startpost, you indeed don't do that)

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 09-Dec-2006 11:25:27   

I amended my code to account for the passed bucket and also for the typedLists's GetRelationInfo() as follows:

                  Dim bucket As IRelationPredicateBucket = criteria.Bucket
                  If bucket Is Nothing Then
                     bucket = m_employeeRegionsTypedList.GetRelationInfo()
                  Else
                     bucket.PredicateExpression.AddWithAnd(m_employeeRegionsTypedList.GetRelationInfo().PredicateExpression)
                     For Each entRel As EntityRelation In DirectCast(m_employeeRegionsTypedList.GetRelationInfo().Relations, RelationCollection)
                        bucket.Relations.Add(entRel)
                     Next
                  End If

                  adapter.FetchTypedList( _
                   m_employeeRegionsTypedList.GetFieldsInfo(), _
                   m_employeeRegionsTypedList, _
                   bucket, criteria.NumberOfRecordsToReturn, _
                   criteria.Sorter, criteria.AllowDuplicates)

Code is working now but I wanted to confirm with you that this is the write way to integrate the typedLists's GetRelationInfo() into the function's own bucket object

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 09-Dec-2006 12:15:18   

Request the bucket from the typedlist once, and then just add the predicates and relations from the criteria bucket to that bucket.

The reason for that is that you then have the proper chaining in relations: in that case the relations from the typedlist are first, so any added relation will be connectable to the pack of relations already in the relationcollection of the bucket.

Frans Bouma | Lead developer LLBLGen Pro