
I have this model.
Rule.
A Company can have multiple service
The Problem
User can enter a list of service name(list of string) and then can retrieve a company which has that list of service.
Question
How can i do this? The first solution that comes to my mind is to join the table first and then use the lambda expression from the joined table. Any other solution?
You can do it with Where():
Companies.Where(c => requiredServices.All(s => c.Services.Contains(s)))
If List<string> is used then:
Companies.Where(company => serviceNames.All(
serviceName => company.Services.Any(service => service.Service_Name == serviceName)))
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