I\'ve got two generic base classes. The second generic class has a constraint on its parameter of the first class.
abstract class FirstClass {...}
This is actually an answer to Interface with two generic parameters, solve one automatically which has been marked as duplicate of this question.
You could declare a bunch of interfaces with a specific Id type. Not a perfect solution, but simplifies the declaration of entity classes.
public interface IIntPersistentEntityService
: IPersistentEntityService
where TPersistentEntity : IPersistentEntity
{
}
public interface IStringPersistentEntityService
: IPersistentEntityService
where TPersistentEntity : IPersistentEntity
{
}
Then the User class can be declared like this:
public class UserService : IIntPersistentEntityService
{
public User Get(int id)
{
throw new NotImplementedException();
}
}
You will get a compiler error if you have not the matching Id type.