score:12

Accepted answer

You can do something like this:

public interface IEntity<T>
{
    IQueryable<T> GetAll();
}

public class Dealer : IEntity<Dealer>
{
   public IQueryable<Dealer> GetAll() { }
}

score:3

You just need to make IEntity generic itself. Then, use the type parameter in the definition of GetAll().

Here's how you'd change your code:

public interface IEntity<TListItemType>
{
     // stuff snipped

     IQueryable<TListItemType> GetAll();
}

public class Dealer : IEntity<Dealer>
{
   public IQueryable<Dealer> GetAll() { // some impl here }
}

score:1

Adding Save(), Validate(), etc. logic to your domain object (which is what a Dealer is, I guess) is not the best idea in the world as it violates SRP.


Related Articles