I have fetches in my code that use common 'prefetches'. So, I simply add a method like:
public static void PrefetchPath_AddFullEntity(IPrefetchPath prefetchPath)
{
prefetchPath.Add(ThisEntity.PrefetchPathSomeRelationShip);
prefetchPath.Add(ThisEntity.PrefetchPathSomeRelationShip2);
prefetchPath.Add(ThisEntity.PrefetchPathSomeRelationShip3);
}
The code to call it:
PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.ThisEntity);
ThisEntity.PrefetchPath_AddFullEntity(prefetchPath);
thisEntity.FetchUsingUCSomeUniqueConstraint(value, prefetchPath);
Note, I do not create the PrefetchPath, but rather add to it. This enables you to combine them together. For example if you had an Entity that contained the ThisEntity above, you could do a full fetch on it by calling:
PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.ContainingEntity);
ThisEntity.PrefetchPath_AddFullEntity(prefetchPath.Add(ContainingEntity.PrefetchPathThisEntity).SubPath);
containingEntity.FetchUsingUCSomeUniqueConstraint(value, prefetchPath);
Works fine. (If you have a better suggestion on how to do this, let me know).
The question/problem is when I have a target per entity hierarchy. If I have EntityB that inherits from EntityA and they have some or all prefetch relationships the same, I end up writing duplicate code. (Note the NEW keyword on the second method, since it inherited the first one). I am assuming this duplicate code is necessary - because if I used the prefetch path from EntityA for an EntityB - it would use the wrong tables.
public static void PrefetchPath_AddFullEntity(IPrefetchPath prefetchPath)
{
prefetchPath.Add(EntityA.PrefetchPathSomeRelationShip);
prefetchPath.Add(EntityA.PrefetchPathSomeRelationShip2);
prefetchPath.Add(EntityA.PrefetchPathSomeRelationShip3);
}
new public static void PrefetchPath_AddFullEntity(IPrefetchPath prefetchPath)
{
prefetchPath.Add(EntityB.PrefetchPathSomeRelationShip);
prefetchPath.Add(EntityB.PrefetchPathSomeRelationShip2);
prefetchPath.Add(EntityB.PrefetchPathSomeRelationShip3);
}
Do you have any ideas/suggestions/workarounds so I do not have to do this - or is this just the best way to do this.