0

I have say three tables.

Projects

  • Id
  • Name

Categories

  • Id
  • Name

ProjectCategories

  • Id
  • ProjectId
  • CategoryId

I now have an array of strings which represents categories the user has elected to search on. I now need to find all the projects that have those category attached to them.

I tried;

string[] searchTerms = new string[2];
searchTerms[0] = "paint";
searchTerms[1] = "painting";

IQueryable<Project> projects = (from category in dc.ProjectCategories
where searchTerms.Any(val => category.Category.Name.Contains(val))
select category.Project).Distinct();

But I get the error;

{"Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator."}

1 Answer 1

1

Unless I'm mistaking your meaning, which is possible, I think you can just do a contains with the searchTerms

where searchTerms.Contains( category.Category.Name )

this will translate into SQL as

... WHERE Name IN ('paint','painting') ...
Sign up to request clarification or add additional context in comments.

1 Comment

Argh! So easy when you see it. Thanks @tv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.