What does "The type T must be a reference type in order to use it as parameter" mean?
Solution 1:
If you look at the definition of DbSet<TEntity>
:
public class DbSet<TEntity> : DbQuery<TEntity>, IDbSet<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, IQueryable, IEnumerable, IInternalSetAdapter
where TEntity : class
Because it has a type constraint
that the generic type must be a class
then you must initialize it with a type that also matches this condition:
public class GenericRecordController<T> : Controller where T : class
{ ... }
Solution 2:
They apparently have a constraint on the generic type.
All you need to change is:
public class GenericRecordController<T> : Controller where T : class
This tells the compiler that only reference types may be supplied as a type for T.
Solution 3:
You can do it on just a method as well:
public bool HasKey<T>(T obj) where T : class
{
return _db.Entry<T>(obj).IsKeySet;
}