Qeefahs wrote:
I am thinking of using the adapter templates and would like to centralize all the DataAcessAdapter calls into a centralized location, including all calls to fetch and save entities and entities collections. Any Idea of whats the best ideas for doing such thing?
Not 100% sure I understand your question, but . . .
When I start a project using LLBLGen Pro, I generally create a static utility class for entity fetches, entity collection fetches, and saves (one class each). Basically each is a wrapper for specific DataAccessAdapter functions, and I only expose the functionality I need--as I need more functions of the DataAccessAdapter (or overloads of a function), I add them to my class.
Posting complete classes from my current project might be confusing, as some of the methods are domain-sepcific. But one common example from my fetch utility, which allows fetching entities with single-field primary keys:
internal static IEntity2 FetchEntityByType(object primaryKey, EntityType type)
{
return FetchEntityByType(primaryKey, null, type);
}
internal static IEntity2 FetchEntityByType(object primaryKey, IPrefetchPath2 prePath, EntityType type)
{
IEntity2 entity = (IEntity2)GeneralEntityFactory.Create(type);
using (FetchAdapter adapter = new FetchAdapter())
{
((IEntityField2)(entity.Fields.PrimaryKeyFields[0])).CurrentValue = primaryKey;
adapter.FetchEntity(entity, prePath);
if (entity.Fields.State != EntityState.Fetched)
{
throw new EntityNotFoundException("Entity with ID: " + primaryKey.ToString() + " not found.");
}
return entity;
}
}
"FetchAdapter" is my derived version of the DataAccessAdapter, if that wasn't clear.
HTH,
Phil