我正在尝试调用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>>
尝试转换到列表并遇到一些麻烦。
答案 0 :(得分:7)
你遗漏了一些括号:
var departments = (from dept in mesEntity.ScanningDepartments
select dept.Department).ToList();
您的代码在ToList()
上调用dept.Department
,而不是整个查询。