I'm wanting to do the something similar - that is filter and join on fields and tables that are created at runtime. I'm using 1.0.2005.1 and Adapter and have done the following:
- Created an ExtensionField entity derived from EntityField2
- I have a routine which adds extension fields to my dynamically created lists. It creates instances of the ExtensionField entities and adds them to the list after doing a Fields.Expand.
- In our custom DataAccessAdapter, I've overridden GetFieldPersistenceInfo to do the following:
protected override IFieldPersistenceInfo GetFieldPersistenceInfo(IEntityField2 field)
{
if(field is ExtensionField)
{
return (field as ExtensionField).GetFieldPersistenceInfo();
}
else
{
return base.GetFieldPersistenceInfo(field);
}
}
- The ExtensionField.GetFieldPersistenceInfo returns the appropriate IFieldPersistenceInfo object.
So far so good.
But now I want to add the table that the extension field appears in to my lists relation collection. Part of the "Add Extension Fields" routine adds appropriate relations. I've copied some code from the generated code to do this...and I thought I had it pretty right using code like:
relation1 = new EntityRelation(RelationType.OneToOne);
relation1.AddEntityFieldPair(EntityFieldFactory.Create(DOCUMENTBASEFieldIndex.ID),
CreateIDEntityField(documentExtension.TABLENAME, "DOCUMENTBASEID"));
relation1.StartEntityIsPkSide = false;
relation1.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("DOCUMENTBASEEntity", false);
relation1.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo(documentExtension.TABLENAME, true);
All seems ok, but when I do my adapter.FetchTypedList, I get an exception:
System.NullReferenceException : Object reference not set to an instance of an object.
at SD.LLBLGen.Pro.ORMSupportClasses.InheritanceInfoProviderBase.GetHierarchyRelations(ArrayList entityNames)
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)
My extension fields and tables aren't in an inheritance relationship with my base table, however since for all generated relations there is code to set the InheritanceInfo, I assume that this is needed. (I also get the same exception if I don't set the InheritanceInfo properties).
Any ideas what I'm missing which is causing this exception? I think I'm missing something defining the "Entity" since the GetHierarchyRelations call gets passed an ArrayList of entityNames.