What's the easiest way of getting the LLBLGenType (the enum) from the runtime type of the LLBLGen Entity (i.e. the Type object). So far I haven't found an easier way to do it than creating an instance of the type via reflection and casting it to IEntity2 (I'm using Adapter in C#).
My motivation for doing this is to write a generic fetch method like this:
public TEntity FetchEntity<TEntity>(int entityId, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields) where TEntity : EntityBase2, IEntity2
{
TEntity ent = ReflectionHelper.CreateInstance<TEntity>();
return (TEntity)FetchEntity((EntityType)ent.LLBLGenProEntityTypeValue, entityId, prefetchPath, excludedIncludedFields);
}
private IEntity2 FetchEntity(EntityType entityType, int entityId, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields)
{
IEntity2 entity = GeneralEntityFactory.Create(entityType);
entity.PrimaryKeyFields[0].CurrentValue = entityId;
var adapter = CreateAdapter();
adapter.FetchEntity(entity, prefetchPath, null, excludedIncludedFields);
return entity;
}
I'm aware that the above code assumes that all entities have a single int primary key, but I'm happy with that.