I am using entity framework code first approach, and I am building a generic Repository class that provides data access. In this class I want an Add(T entity)
m
Add a generic constraint to your repository class:
public class Repository<TEntity> where TEntity : class
I have literally just posted this question but I have found a way around the problem - use the Set(Type t) method instead of the generic version like so:
public TEntity Add(TEntity entity)
{
return (TEntity)_database.Set(typeof(TEntity)).Add(entity);
}
A little bit of intellisense inspection goes a long way! Hope this helps someone...