I am not sure if this is possible, but I have started a new project and I am trying to clean up the way I work with the DbContext. I am trying to do this by
you can have your entities like this :
public interface IEntity
{
TKey Id { get; }
}
public class Question : IEntity
{
public TPrimaryKey Id { get; set; }
}
then your repository like this :
public class Repository where TEntity: IEntity
{
protected readonly DbContext _dbContext;
protected readonly DbSet _dbEntitySet;
public Repository(InteractiveChoicesContext dbContext)
{
_dbContext = dbContext;
_dbEntitySet = dbContext.Set();
}
}
and in my opinion, this is the best way to do it "Generic".