Mar*_*uta 3 c# asp.net-mvc linq-to-entities
我正在尝试调用GetScanningLogOnSettings(),查询ScanningDepartments表以获取部门,然后创建实例ApplicationLogOnModel,将查询结果分配给其中的变量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;
}
Run Code Online (Sandbox Code Playgroud)
它给了我:
"无法隐式转换
'System.Linq.IQueryable<System.Collections.Generic.List<char>>为'System.Collections.Generic.List<Models.Department>'
尝试转换为列表,我遇到了一些麻烦.
你遗漏了一些括号:
var departments = (from dept in mesEntity.ScanningDepartments
select dept.Department).ToList();
Run Code Online (Sandbox Code Playgroud)
你的代码调用ToList()上dept.Department,而不是整个查询.
| 归档时间: |
|
| 查看次数: |
5556 次 |
| 最近记录: |