LINQ to SQL从字符串创建查询

sd_*_*ula 2 c# sql linq asp.net

我有一个dbml上下文查询,看起来像这样:

var SQLQueryResult = (from activeTable in context.activeTabless
                      where (
                               activeTable .AssignedTo == "Person1" ||
                               activeTable .AssignedTo == "Person2" ||
                               activeTable .AssignedTo == "Person3")
                    select new { ... });
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何根据用户选择更新where字段,使其可以包含任意数量or(不仅仅是上述三个)?

假设数字可以来自列表或数组.这对于直接SQL来说很简单,但不确定如何通过Linq to SQL来实现.

nvo*_*igt 5

var persons = new []{"Person1", "Person2", "Person3"};
var SQLQueryResult = (from activeTable in context.activeTabless
                      where ( persons.Contains(activeTable .AssignedTo))
                    select new { ... });
Run Code Online (Sandbox Code Playgroud)

您可以使用.Contains()扩展方法检查集合中是否存在某些内容IEnumerable.