Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有IN列表的动态Linq_Linq_Dynamic Linq_Dynamic Linq Core - Fatal编程技术网

具有IN列表的动态Linq

具有IN列表的动态Linq,linq,dynamic-linq,dynamic-linq-core,Linq,Dynamic Linq,Dynamic Linq Core,我正在使用EF Dynamic Linq库基于用户输入构造动态查询 我可以像这样设置where子句来搜索用户角色=1: var users = await _db.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role) .Where(x => x.IsActive == true) .Where("x => x.UserRoles.

我正在使用EF Dynamic Linq库基于用户输入构造动态查询

我可以像这样设置where子句来搜索用户角色=1:

            var users = await _db.Users.Include(x => x.UserRoles).ThenInclude(x => x.Role)
            .Where(x => x.IsActive == true) 
            .Where("x => x.UserRoles.Any(y => y.RoleId == 1)")
在这个查询中,角色id“1”来自另一个源,就像用户输入一样。如何修改此查询以搜索多个角色ID?传入的字符串值类似于“1,2,4”。如何在搜索中使用此字符串查找具有任何角色的所有用户?我尝试使用new[]{1,2,4}之类的东西,但不确定如何将其放入字符串中。

int[]roles=new int[]{1,2,3};
int[] roles = new int[] { 1, 2, 3 };
IEnumerable<User> users = await db.Users
    .Include(x => x.UserRoles)
    .ThenInclude(x => x.Role)
    .Where(x => x.IsActive == true && x.UserRoles.Any(y => roles.Contains(y)));
IEnumerable users=wait db.users .Include(x=>x.UserRoles) .然后包括(x=>x.Role) 其中(x=>x.IsActive==true&&x.UserRoles.Any(y=>roles.Contains(y));
对不起,我没有说清楚,由于用户输入的性质,我不得不使用动态sql查询。字符串是动态构造的。啊,好吧,我误解了你的问题。这有用吗?