Tuesday, 10 September 2013

Chain Lambda Linq

Chain Lambda Linq

public class Translation
{
public string LanguageCode { get; set; }
public string Value { get; set; }
}
public class tblEnumJobFunction
{
public string strEnum { get; set; }
public List<Translation> mlgValue { get; set; }
//mlgValue->MultiLingualValue
}
I have a List<tblEnumJobFunction> JobFunctionList with some data.
Example Data:
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";
I can filter this list with LINQ by given country Code and happy with it.
The Question is how can I write equivalent below query syntax by lambda
with the List/Collection extensions?
It is a cascade/chain query; looking into a list that is inside another list.
This query syntax is working OK.
string CountryCode ="EN";
var Query = from jobfunction in JobFunctionList
from translation in jobfunction.mlgValue
where translation.LanguageCode == CountryCode //'EN'
select translation;
The Result is;
List<string> JobList;
foreach (var translationitem in Query)
{
JobList.Add(translationitem .Value);
}
now I have
JobList[0]="Manager";
JobList[1]="Student";
For CountryCode="DE" I have;
JobList[0]="Geschäftsführer";
JobList[1]="Schüler";
Is there any way to write above query syntax with lambda similiar to this
one?
JobFunctionList.Select(a=>a.mlgValue).Where(b=>b....)...

No comments:

Post a Comment