Change your interface to be generic:
public interface IQueryEntities<TId>
{
IQueryable<TEntity> Query<TEntity>() where TEntity : Entity<TId>;
}
and then when you implement it:
public class EntityAbc : Entity<string>, IQueryEntities<string>
or maybe event his:
public abstract class Entity<TId> : IEquatable<Entity<TId>>, IQueryEntities<TId>
So to update to reflect the comments. Making that interface generic is still the approach. If you didn't want the entities implementing the interface, no problem, you could do this:
public class QueryEntities<TId> : IQueryEntities<TId>
{
public IQueryable<TEntity> Query<TEntity>()
where TEntity : Entity<TId>
{
...
}
}
Using that might look like this:
var queries = new QueryEntities<string>();
queries.Query<EntityAbc>();
But, you're not going to be able to send any entity into that interface unless you make the method itself receive the TIn
. If you were to make the method itself generic like that the code would be this of course:
var queries = new QueryEntities();
queries.Query<EntityAbc, string>();
the interface for that looks like this:
public interface IQueryEntities
{
IQueryable<TEntity> Query<TEntity, TId>() where TEntity : Entity<TId>;
}
but you don't want that.