How to get parent model as a result. I want to get MasterData type as a result. i want to use where condition in Attributes but i want to receive Master Data Type as a result
var result= MasterData.SelectMany(ca => ca.Attributes)
.Where(x => MasterDataAttId_All.Contains(x.AttributeId))
.ToList();
Loading
Jignesh KumarPosted Nov 28, 2024, 6:25 AM
Hello Mert,
Please use below query which will help you out,
Sangeetha SPosted Nov 28, 2024, 4:24 AM
To retrieving the parent model (Master Data type) while applying a filter condition on the child attributes, you can use a combination of
Where,Select, and possiblyDistinctif needed.Instead of using
Explanation:SelectMany, you want to filter theMasterDatabased on the condition of its attributes and then return theMasterDataobjects themselves. Here’s how you can do that:Where: This filters theMasterDatacollection.Any: This checks if any of theAttributesin eachMasterDataobject satisfy the condition (i.e., if theirAttributeIdis contained inMasterDataAttId_All).ToList(): This converts the filtered result back into a list ofMasterDataobjects.Jayraj ChhayaPosted Nov 27, 2024, 2:45 PM
Hi Mert AKYILDIZ,
To achieve the desired outcome of retrieving the
MasterDatatype while applying a condition on itsAttributes, you can utilize theWhereclause in conjunction withAnyto filter the parent model based on the attributes.