I have a web page where the user can restrict results based on three different multi select choices (please see attached picture).
A bit of background. Documents have many sectors, companies and analysts assigned to them. My EF objects have navigation properties which means I don't need to write explicit JOINS to get the data I need.
My problem is I can't construct the LINQ query I need to get the results I need. Using SQL it would be simple and I could easily use a combination of JOINS and WHERE IN ('Blah', 'Another blah'). In my controller I have the following code:
public JsonResult FilterResearch(FilterResearchModel filterResearch)
{
var db = new Context();
// home model
var model = new HomeModel();
var selectedSectors = from s in db.Sectors
where filterResearch.SelectedSectors.Contains(s.Name)
select s;
var selectedCompanies = from c in db.Companies
where filterResearch.SelectedCompanies.Contains(c.Name)
select c;
var selectedAnalysts = from a in db.Analysts
where filterResearch.SelectedAnalysts.Contains(a.Name)
select a;
var filteredResults = from d in db.Documents
where selectedSectors.Contains(d.Sectors)
select d;
FilterResearch.Selected"Something" are string arrays. My "filteredResults" query is what should contain the filtered documents I plan to return.
EDIT Some people have commented on the fact I'm not being clear. I'm trying to filter my documents based on 3 string arrays. Each of these string arrays are navigation properties in the "document" object. On the client the user has three multi select controls so each array can have more than one element. Now they can choose any of the three and choose as many options as they wish.
THIS IS THE PROBLEM When I compile it I get the following error: "cannot convert from 'System.Linq.IQueryable' to 'System.Linq.ParallelQuery>"
EDIT AGAIN Picture of error included. It occurs on "where selectedSectors.Contains(d.Sectors)"
I have checked:
- Convert SQL to LINQ to Entities WHERE IN clause
- LINQ to Entities - Where IN clause in query [duplicate]
- Where IN clause in LINQ [duplicate]
with little luck. Is there a way where I can just say "filter the documents based on the companies AND sectors AND analysts?