1
Answer

How to check child table contains any item from array

ravi sharma

ravi sharma

8y
287
1
Hi,
 
I have two tables Recommendation and RecommendationMemberDetails. Both table contains MemberId.
Recommendation table contains my id as MemberId and RecommendationMemberDetail table will contain other peoples Id as MemberId with recommendationId.
 
Recommendation
 ----------------------------
RecommendationId (PK)
MemberId
 
RecommendationMemberDetail
-------------------------------------------
 Id
RecommendationId
MemberId
 
 
Now I will select multiple contact from Contact list and I need to fetch such Recommendation Where MemberId of Recommendation or RecommendationMemberDetails contains MemberId from contactlist.
 
Following is the query.
 
var data1 = _context.Recommendations.Where(x => listMembers.Contains(x.MemberId) || (x.RecommendationMemberDetail.Count() > 0 && listMembers.Contains(x.RecommendationMemberDetail.Select(y => y.MemberId).ToString())) && x.CSM_Approve != "p");
 
Please suggest.
 
 
 
Answers (1)