将IQueryable列表转换为通用列表?

时间:2013-02-19 15:52:44

标签: c# asp.net-mvc linq-to-entities

我正在尝试调用GetScanningLogOnSettings(),查询ScanningDepartments表以获取部门,然后创建ApplicationLogOnModel的实例,将查询结果分配给{{中的变量1}},并返回结果。

ApplicationLogOnModel

它给了我:

  

“无法隐式转换类型   private ApplicationLogOnModel GetScanningLogOnSettings() { var mesEntity = new MESEntities(); var departments = from dept in mesEntity.ScanningDepartments select dept.Department.ToList(); ApplicationLogOnModel depts = new ApplicationLogOnModel() { Department = departments }; return depts; } 来   'System.Linq.IQueryable<System.Collections.Generic.List<char>>

尝试转换到列表并遇到一些麻烦。

1 个答案:

答案 0 :(得分:7)

你遗漏了一些括号:

var departments = (from dept in mesEntity.ScanningDepartments
                   select dept.Department).ToList();

您的代码在ToList()上调用dept.Department,而不是整个查询。