调用一种方法,将 return 员工列表从 Class 库调用到 UI DataGridView 项目 C# Entity Framework

Call a method that return a list of employee from Class Library to UI DataGridView project C# Entity Framework

我是 Entity Framework 和 LINQ 的新手 我有两个项目,一个是我的 class 库,另一个是我的 UI 项目 我正在努力显示来自 return 我的 class 库列表的方法的员工列表 这是我的 class:

    public static class ViewEmployeesDataManager
    {
        public static List<Employee> ViewManagerEmployees()
        {
            using (var context = new HRSystemContext())
            {
                var query = from empolyee in context.Employees
                            select new { 
                                Name = empolyee.FullName,
                                JobTitle = empolyee.JobTitle,
                                Mobile = empolyee.Mobile};

                return query.ToList();

我是这样称呼它的:

dataGridView1.DataSource=ViewEmployeesDataManager.ViewManagerEmployees();

我遇到了这个错误

error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<<anonymous type: string Name, string JobTitle, string Mobile>>' to 'System.Collections.Generic.List<DataAccessLayer.Employee>

任何人都可以帮忙

更新: 我通过在列表中添加 Object 而不是 Employee 来解决错误 成功了

public static List<Object> ShowingEmployeeInfo()
    {
        using (var context = new HRSystemContext())
        {
            var employee = from row in context.Employees
                            where row.Username == EmployeeDataManager.currentUser
                            select new {
                                Id = row.Id,
                                Name = row.FullName,
                                Job = row.JobTitle,
                                Mobile = row.Mobile,
                                Manager = row.Manager.FullName
                            };
            return employee.ToList<Object>();

        }
    }