I am trying to implement a generic GetById(T id)
method which will cater for types which may have differing ID types. In my example, I have an entity which has
public interface IEntity where TId : class
{
TId Id { get; set; }
}
The where TId : class
constraint requires every implementation to have a Id which derives from object which is not true for value types like int.
Thats what the error message tells you: The type 'int' must be a reference type in order to use it as parameter 'TId' in the generic type of method IEntity
Just remove the constraint where TId : class
from IEntity