I’ve created a method which accepts an IEntity object, table name (string) and column name (string). The method loops through all fields in the IEntity object and if it finds a field with the same name as the column name passed into the method it returns its value, as seen below.
for (int f = 0; f < _objEntity.Fields.Count; f++)
{
if (_objEntity.Fields[f].Name == FieldName)
{
if (_objEntity.Fields[f].CurrentValue.ToString() == FieldValue)
returnBool = true;
}
}
The problem we’ve got is that sometimes the table name passed into this method isn’t the name of the IEntity table. In these cases I’ve created a method that loops through all tables related to the original IEntity object to see whether its name matches the table name passed into the method, as seen below.
List<IEntity> relations = _objEntity.GetDependentRelatedEntities();
foreach(IEntity iEnt in relations)
{
if (iEnt.LLBLGenProEntityName == EntityName) {
_objEntity = iEnt;
break;
}
}
This pretty much works perfectly, except for the fact that “GetDependentRelatedEntities()” only actually returns anything IF PreFetchPaths were used when fetching the data for the IEntity object. It seems to me that it would be rather silly to have to force every single preFetchPath on the IEntity so that the “GetDependentRelatedEntities()” method works properly.
Is there any way to loop through all related tables on an IEntity object, compare the name of the related table with a local variable and then IF a match is found actually populate that related entity with data (based on its relationship with the original IEntity)?? As a test I placed the following line of code just before the “GetDependentRelatedEntities()” line above. Doing this then meant that when executing “GetDependentRelatedEntities()” it finds and returns the Client table relation... everything then works perfectly. This is of course a complete hack and assums that if the related table will ALWAYS be “Client”.
((UserEntity)objEntity).Client.Refetch();
This is proving to be a mamoth of a problem for us, any help would be much appreciated.