3
我試圖撥打GetScanningLogOnSettings()
,查詢ScanningDepartments
表獲取部門,然後創建ApplicationLogOnModel
的實例,將查詢的結果分配給ApplicationLogOnModel
中的變量,並返回結果。將IQueryable列表轉換爲通用列表?
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>>
到'System.Collections.Generic.List<Models.Department>'
試圖轉換到列表時遇到了一點小麻煩
它現在說「無法隱式轉換類型‘System.Collections.Generic.List爲’System.Collections.Generic.List –
2013-02-19 16:01:13
@MarkSaluta:這又是一個問題,而不是這個問題的範圍。最有可能的是,'dept.Department'返回一個字符串,'ApplicationLogOnModel.Department'不是一個字符串列表,而是'Models.Department'實例。 – 2013-02-19 16:04:22