我经常需要类似这样的查询:
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]).Contains([10007].City)....”