I am trying to use the template pattern and C# generics to write a utility that will list the entities in the database for any DbSet within Any DbContext. I presume I need three generics:
public class lister<TDbSet, TContext, TEntity>
where TDbSet : DbSet<IPEntity>
where TContext : DbContext
were TEntity : IPEntity
(IPEntity is an abstract base class for all of our entity classes.) Everything seems to be happy except for trying to write a LINQ expression to get the result set. Since "TDbSwt" is actually a MEMBER of TContext, I cannot figure out if LINQ will let you do something like:
from x in TContext.TDbSet select x
It certainly does not like THAT line, whether or not I prefix TDbSet with TContext or not.
Anyone know how I could set this up? right now I have separate (very small, but still one for each entity) class for the entity and LINQ specifics, but as we grow from dozens to hundreds to perhaps thousands of entities, I would like to find a more compact and elegant solution.
Thanks.
TDbSetto thelisterclass and use an instance of that in your query.TEntitywasMyEntity,TDbSetwasDBSet<MyEntity>andTContextwasDbContext, then your linq statement would read asfrom x in DbContext.DbSet<MyEntity> select x, which doesn't make sense.