我試圖削減這個LINQ下來重構Linq查詢
var sys = db.tlkpSystems
.Where(a => db.tlkpSettings.Where(e => e.Hidden < 3)
.Select(o => o.System)
.ToList().Contains(a.System)) //cannot get this part in?
.OrderBy(a => a.SystemName).ToList();
foreach (var item in sys)
model.Add(new SettingSystem {
System = item.System,
SystemName = item.SystemName
});
我曾嘗試以下:
List<SettingSystem> model = new List<SettingSystem>();
model = db.tlkpSettings.Where(e => e.Hidden < 3)
.OrderBy(e => e.Setting)
.Select(e => new SettingSystem
{
System = e.System,
SystemName = e.Setting
}).ToList();
我怎樣才能調用。載我的查詢(a.System)部分?
感謝
@Mafii任何原因.ToList()不應該被使用?我是新來的linq – Haris
這是LINQ to Entities查詢嗎? –
是的。 http://stackoverflow.com/questions/15516462/is-there-a-performance-impact-when-calling-tolist – uTeisT