I have EntityBase abstract class which normally all of my entities inherit from. It takes a generic type that specifies the type of the Id property (e.g. int or Guid). EntityBase also contains some logic to determine equality between entities.
public abstract class EntityBase<T>
{
public T Id { get; private set; }
...
}
In my .Net Core 2.2 web application, I'm using Asp.Net Identity and I have an entity named ApplicationUser that must inherit from Microsoft.AspNetCore.Identity.IdentityUser. Because it's not possible to inherit from multiple base classes, I can't inherit from EntityBase.
So, I created an interface named IEntity which both EntityBase and ApplicationUser implement
public interface IEntity<T>
{
T Id { get; }
}
I have a IRepository interface that with a generic type that must be an entity. I don't care what the type of the Id is on that entity. I just want to be able to say that TEntity just needs to be some IEntity and I don't care if it's IEntity or IEntity. Something like the below. Is this possible?
public interface IRepository<TEntity> where TEntity : IEntity
{
}