I must be getting good at thinking outside the box
Ok I modified entityFactories.template -
First I made the assertion that I only want to do this generic fetch for entities that have a PK of type int (which means I later have to exclude the ones that have a guid pk)
Next I added a middle interface:
public interface IEntityFactoryB : IEntityFactory
{
IEntity Create(int PKId);
}
Then I changed the entity factory class def to inherit from the new new middle interface:
public <[If UsePartialClasses]>partial <[EndIf]>class <[CurrentEntityName]>EntityFactory : IEntityFactoryB
Then in the entity factory class I added the new interface method def, notice I took a brute force exclusion of 5 entities that have non int PKs:
/// <summary>Creates a new, fetched <[CurrentEntityName]>Entity object.</summary>
/// <returns>A new, fetched <[CurrentEntityName]>Entity object.</returns>
public virtual IEntity Create(int PKId)
{
IEntity toReturn = null;
<[If Not StringValueEquals CurrentEntityName "EmployeeAux,TblEmailAddress,ContentData,SQLLog,SQLLOGKEYS"]>
toReturn = new <[CurrentEntityName]>Entity(PKId);<[EndIf]>
return toReturn;
}
Finally I added a new static method to the GeneralEntityFactory class at the bottom:
/// <summary>Creates a new, empty Entity object of the type specified</summary>
/// <param name="entityTypeToCreate">The entity type to create.</param>
/// <returns>A new, empty Entity object.</returns>
public static IEntity Create(EntityType entityTypeToCreate, int PKId)
{
IEntityFactoryB factoryToUse = null;
switch(entityTypeToCreate)
{
<[Foreach Entity CrLf]> case <[RootNamespace]>.EntityType.<[CurrentEntityName]>Entity:
factoryToUse = new <[CurrentEntityName]>EntityFactory();
break;<[NextForeach]>
}
return factoryToUse.Create(PKId);
}
VOILA! I can now create and fetch entities by EntityType and a PKID value.