使用泛型类型';System.Collections.Generic.List<;T>';在IRep

本文关键字:lt gt IRep List Collections 泛型类型 System Generic | 更新日期: 2023-09-27 17:59:36

我在下面提到的代码中遇到了一个问题。它问了我1个论点。I存放

public interface IUserRepository
{
    List GetAll(); // Error shows me here then i change this to List<User> GetAll(); but still getting the error.
}

存储库

public class UserRepository : IUserRepository
{
    private IDbConnection _db = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
    public List<User> GetAll()
    {
        return this._db.Query<User>("SELECT * FROM Users").ToList();
    }
}

使用泛型类型';System.Collections.Generic.List<;T>';在IRep

您应该尝试使用:

public interface IUserRepository<T>
{
    List<T> GetAll(); 
}

然后:

public class UserRepository : IUserRepository<User>
{
    private IDbConnection _db = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
    public List<User> GetAll()
    {
        return this._db.Query<User>("SELECT * FROM Users").ToList();
    }
}