ravi sharma

ravi sharma

  • NA
  • 87
  • 15.5k

How to check child table contains any item from array

Sep 2 2016 6:38 AM
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)