与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]。城市),不支持......”