C# 链Lambda Linq
我可以根据给定的国家代码使用LINQ筛选此列表,并对此感到满意 问题是如何通过lambda编写具有列表/集合扩展的等价查询语法 这是一个级联/链查询;查看另一个列表中的列表 此查询语法工作正常C# 链Lambda Linq,c#,linq,lambda,cascade,chain,C#,Linq,Lambda,Cascade,Chain,我可以根据给定的国家代码使用LINQ筛选此列表,并对此感到满意 问题是如何通过lambda编写具有列表/集合扩展的等价查询语法 这是一个级联/链查询;查看另一个列表中的列表 此查询语法工作正常 JobFunctionList[0].strEnum="ENUM_Manager"; JobFunctionList[0].mlgValue[0].LanguageCode ="EN"; JobFunctionList[0].mlgValue[0].Value="Manager"; JobFunctio
JobFunctionList[0].strEnum="ENUM_Manager";
JobFunctionList[0].mlgValue[0].LanguageCode ="EN";
JobFunctionList[0].mlgValue[0].Value="Manager";
JobFunctionList[0].mlgValue[1].LanguageCode ="DE";
JobFunctionList[0].mlgValue[1].Value="Geschäftsführer";
JobFunctionList[1].strEnum="ENUM_Student";
JobFunctionList[1].mlgValue[0].LanguageCode ="EN";
JobFunctionList[1].mlgValue[0].Value="Student";
JobFunctionList[1].mlgValue[1].LanguageCode ="DE";
JobFunctionList[1].mlgValue[1].Value="Schüler";
结果是
string CountryCode ="EN";
var Query = from jobfunction in JobFunctionList
from translation in jobfunction.mlgValue
where translation.LanguageCode == CountryCode //'EN'
select translation;
有没有办法用lambda编写与此类似的查询语法
JobList[0]="Manager";
JobList[1]="Student";
For CountryCode="DE" I have;
JobList[0]="Geschäftsführer";
JobList[1]="Schüler";
两个来自子句的
,如您的示例中所示,使序列平坦化。您需要使用SelectMany
扩展方法。这可能就是您正在寻找的:
JobFunctionList.Select(a=>a.mlgValue).Where(b=>b....)...
List JobList=Objs.SelectMany(jobFunction=>jobFunction.mlgValue)
.Where(translation=>translation.LanguageCode==CountryCode)
.Select(translation=>translation.Value)
.ToList();
注意:考虑使用良好的名称,即使是在LAMBDAS内具有小范围的形式参数。code>a
、b
、m
、fo
并不是最好的名称。它工作得很好!非常感谢你!我也会按照你的建议进行命名。我会按照你的建议进行命名,并编辑原始问题,以便其他人更好地理解代码。
JobList[0]="Manager";
JobList[1]="Student";
For CountryCode="DE" I have;
JobList[0]="Geschäftsführer";
JobList[1]="Schüler";
JobFunctionList.Select(a=>a.mlgValue).Where(b=>b....)...
List<string> JobList = Objs.SelectMany(jobFunction => jobFunction.mlgValue)
.Where(translation => translation.LanguageCode == CountryCode)
.Select(translation => translation.Value)
.ToList();