與LINQ運營商很多時候我都需要類似這樣的疑問:SQL 'IN' 在Visual Studio LightSwitch中
SELECT * FROM Customers
WHERE City IN ('Paris','London');
我有一些列表(最常見的字符串)。當列表很小(如本例中),它是沒有這樣的問題,我可以寫這樣的事情(C#):
Customers custs = this.DataWorkspace.ApplicationData.Customers;
var filteredcustomers = custs.Where(c=>c.City == "Paris" || c=>c.City == "London");
但如果我有更大的名單,這是一個有點笨拙。 我已經試過這(從一些論壇):
List<string> months = new List<string>() {"Jan", "Feb", "Mar"......"Dec"};
Customers custs = this.DataWorkspace.ApplicationData.Customers;
var filteredcustomers = custs.Where(c => months.Contains(c.City));
,但我得到運行時錯誤:
「{System.NotSupportedException: 表達式的值(System.Collections.Generic.List`1 [ 。System.String])包含([10007]。城市),不支持......」