Returning generic types from Repository Is it bad design if I create repostory with methods that returns generic types. For example in AccountsRepository if I have:

public class Repository&lt;T&gt; : IRepository&lt;T&gt;
where T : class
{
}

public class AccountsRepository&lt;TUser&gt; : 
Repository&lt;User&gt;,IAccountsRepository
    where TUser : class,IUser,new()
    {
      public TUser GetUserByUserName(string username)
      {
       return this.context.User.Where(s =&gt; 
       s.UserName.Equals(username)).Select(c=&gt;new TUser(){ Password =c.Password }).FirstOrDefault();
      }
    }


Is this the proper way of doing that. So It's something like I return DTO object but it is generic type. So my classes using repository doesn't have to know what types are the objects in database.
Is it bad design if I create repostory with methods that returns generic types.


Not at all. It's very useful.


  Is this the proper way of doing that?


I'm not entirely sure because even though you use a generic return type you use the same User table for all of them:


this.context.User



However if the IRepository provides different User tables where each of the different users implement the TUser then I'd say it' fine. Otherwise it would not be that usefull and you could just return the normal User.