简体   繁体   English

基于字符串的Dynamic Linq-Nested Where子句

[英]String based Dynamic Linq - Nested Where clause

I'm doing string based Dynamic Linq and need to apply a nested where clause. 我正在做基于字符串的Dynamic Linq,需要应用嵌套的where子句。

The answer here gets me half way there. 答案在这里让我半途而废。 However, the columns in two tables have matching ids. 但是,两个表中的列具有匹配的ID。 I need to be able to reference via an alias or other, like below: 我需要能够通过别名或其他方式进行引用,如下所示:

rolesCollection
.Where("AssignedUsers.Where(AssignedUsers.TypId == rolesCollection.TypId).Any()");

Any idea how to accomplish this? 任何想法如何做到这一点? I don't have the ability to pass in an object, this has to be purely a string based solution in the context of a genericized API search method. 我没有传递对象的能力,在通用API搜索方法的上下文中,这必须是纯粹基于字符串的解决方案。 This is just an example of what I need ... I don't have the ability to join or anything via code. 这只是我所需要的一个示例……我没有能力通过代码加入或进行任何操作。 I'm looking for the solution in the string based portion of the example code. 我正在示例代码的基于字符串的部分中寻找解决方案。

你想要那样的东西吗?

rolesCollection = rolesCollection.Where(x => assignedUsers.Any(t => t.TypId == x.TypId)).ToList();

The AssignedUsers object should, in this theoretical example, have an AssignedUsers_Typ collection, and you can simply reference below, without having to reference the Typ columns from both tables. 在此理论示例中,AssignedUsers对象应具有AssignedUsers_Typ集合,您可以在下面简单地进行引用,而不必引用两个表中的Typ列。

   rolesCollection.Where("AssignedUsers_Typ.Any()");

I was able to resolve my issue using this solution. 使用此解决方案,我能够解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM