完全混淆了這裏所需的數據類型。將Linq ObjectQuery IQueryable轉換爲IEnumerable
我有這樣的LINQ聲明:
var feat = AllCustomers
.Select(c => c.CustomerServices.SelectMany(cs => cs.CustomerServiceFeatures)
.SelectMany(csf => csf.ConfigElements).Where(ce => ce.Name == "ItemType").Select(ce => ce.Value).Distinct());
它返回所需的數據,並VS告訴我,類型被設定爲:
System.Data.Objects.ObjectQuery<System.Collections.Generic.IEnumerable<string>>
但是我想這個數據添加到字符串列表:
List<string> itemTypes = new List<string>();
itemTypes.AddRange(feat);
但是,這將引發一個錯誤:
Argument 1: cannot convert from 'System.Linq.IQueryable<System.Collections.Generic.IEnumerable<string>>' to 'System.Collections.Generic.IEnumerable<string>'
我無法找到所需的語法來轉換爲正確的類型。誰能幫忙?
乾杯, 馬特
答案在整個這段時間裏,我一直在面對着我,我正在嘗試各種各樣的SelectMany()技巧,除此之外。另外..這個答案是非常困難的谷歌! – 2012-02-13 21:08:25