2021年8月6日 星期五

Lambda Filter Detail

常常忘記這語法所以來記錄一下
情境個人資料內有許多經歷或是學歷
某天人資部需求想撈出那些人是碩士及博士
通常資料表會這樣開
員工資料主檔
public class Staff
{
	public int StaffId { get; set; }
	public string Name { get; set; }
	public List EducationList { get; set; }//多種學歷	
}
學歷檔
public class Education
{
	public int EducationId { get; set; }
	public int EducationType { get; set; }//假設有另一個資料表紀錄ID的意思 碩士是6 博士是7
	public string SchoolName { get; set; }
}
抓取過濾碩士博士
int[] filter = new int[] { 6, 7 };
result = result.Where(x => x.EducationList.Any(y => filter.Contains(y.EducationType))).ToList();