将 iQueryable 转换为列表

Convert iQueryable to List

作为菜鸟,我正在尝试将我的 LINQ 查询结果转换为列表。

错误:

Can not implicitly convert type System.Collections.Generic.List<anonymous type: string fname, string lname> to System.Collections.Generic.List<ConsoleApp01.UserClass>

我试过了

static public void TestSQLRx()
{
    using(UserAccessEntities db = new UserAccessEntities())
    {
        var userlist = from User in db.Users
                       select new
                       {
                           User.fname,
                           User.lname
                       };

        List<Userclass> usertype = new List<Userclass>();

        usertype = userlist.ToList();
    }
}

class Userclass //This is my Userclass class
{
    private string firstname;
    private string lastname;

    public string Firstname { get => firstname; set => firstname = value; }
    public string Lastname { get => lastname; set => lastname = value; }
}

只使用Userclass而不是匿名类型。

var userlist = from User in db.Users
                       select new Userclass()
                       {
                           Firstname  = User.fname,
                           Lastname  = User.lname
                       };