I have 2 classes with different properties
ClassA
int Id
int Name
int Status
ClassB
int ClassAId
string Bprop1
string Bprop2
string Bprop3
...
I have List of ClassA and List of ClassB and i want to get a unique list of ClassA values with the condition
List where ClassA.Id is present with List on property ClassAId
Example:
// given
List<ClassA> {{1,"a"},{2,"b"},{3,"c"},{4,"d"}} etc
Lisst<ClassB> {{1,"aaa","ccc","aasdaf"},{3,"aaa","ccc","aasdaf"}}
// expected result
List<ClassA> {{1,"a"},{3,"c"}}
How can I apply a LINQ query for the same?
This should give you the expected output:-
List<ClassA> resultClassA = classAObj.Where(a => classBObj.Any(b => b.ClassAId == a.Id))
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With