Hello LLBLGen Team:
I have the following requirement: We desire fetch a specific entitity and get all entities relations for that entity, in other words I wish build a graph of all relations. My approach is using the prefetchs paths in order to build a dynamic prefetch through reflection.
This is my code:
var prefetchPath = new PrefetchPath2((int)EntityType.CustomerEntity); [b]<-- ROOT
[/b]
var customerEntityType = typeof(CustomerEntity);
foreach (var propertyPrefetch in customerEntityType.GetProperties(BindingFlags.Public | BindingFlags.Static).Where(x => x.Name.StartsWith("PrefetchPath")).ToList())
{
var prefetchPathElement = (IPrefetchPathElement2)propertyPrefetch.GetValue(null, null);
var entityTypeToFetch = (EntityType)Enum.ToObject(typeof(EntityType), prefetchPathElement.ToFetchEntityType);
var prefetchElement = prefetchPath.Add(prefetchPathElement);
BuildPrefetchPaths(entityTypeToFetch.ToString(), prefetchElement); [b]<--CALL TO RECURSIVE METHOD[/b]
}
}
Recursive Method:
private void BuildPrefetchPaths(string originEntity, IPrefetchPathElement2 prefetchPathElement)
{
var factoryEntity = _factoryManager.Factories.First(f => f.ForEntityName.Equals(originEntity));
var instanceEntity = factoryEntity.Create();
var typeEntity = instanceEntity.GetType();
foreach (var prefetchProperty in typeEntity.GetProperties(BindingFlags.Public | BindingFlags.Static).Where(x => x.Name.StartsWith("Prefetch")).ToList())
{
var prefetchPropertyToAdd = (IPrefetchPathElement2)prefetchProperty.GetValue(null, null);
EntityType entityTypeToFetch = (EntityType)Enum.ToObject(typeof(EntityType), prefetchPropertyToAdd.ToFetchEntityType);
var prefetchElement2 = prefetchPathElement.SubPath.Add(prefetchPropertyToAdd);
BuildPrefetchPaths(entityTypeToFetch.ToString(), prefetchElement2);
}
}
The big problem is does not work because when I call the recursive method of the call to DataAdapter is not retrieve any information and does not throw exception.
It is some strange because if I don't do the call to recursive method inside the method called 'BuildPrefetchPaths' working well. I don't known if exists a restriction for a huge prefetch path.
Can you help me with some comments or ideas? The version that we use is LLBLGen is 4.2 and as additional information the database target have 97 tables.