I made a generic Repository class with a GetById method
public interface IEntity<T>
{
public T Id { get; set; }
}
...
public Product: IEntity<int>
{
public int Id { get; set; }
}
...
public Task<T> GetById<T, TId>(TId id) where T : class, IEntity<TId>
{
return dbContext.Set<T>().FirstOrDefaultAsync(x => x.Id.Equals(id));
}
I want the type be inferred from the parameter when i call it
myRepo.GetById<Product>(pId) //compile error (I want this to work)
myRepo.GetById<Product,int>(pId) //works
I thought the second generic could be inferred from the parameter. Am I missing something or is it not possible?