i want to receive Sections within MasterDataAttId_All bu this code returns all sections if any section id contains MasterDataAttId_All. How to receive Sections that it's id equals any MasterDataAttId_All's id
var result = MasterData.Where(md => md.sections.Any(x => MasterDataAttId_All.Contains(x.SectionId))).ToList()
Linq Question
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 28, 2024, 1:15 AM EST
Hello Mertz,
Please use this query,
var result = MasterData .Where(md => md.sections .Any(x => MasterDataAttId_All.Contains(x.SectionId))).ToList();Tuhin PaulRank #7 · 71.9K reputationPosted Jan 15, 2025, 1:21 PM EST
var result = MasterData.Where(md => md.sections.Any(x => MasterDataAttId_All.Equals(x.SectionId))).ToList();if
MasterDataAttId_Allis a collection of IDs and you want to check if any of theSectionIdmatches with the IDs in the collection, you should use theContainsmethod in a different way.