tags:

views:

99

answers:

2

Here is some code:

//all possible search terms of interest 
searchTerms = from s in dc.SearchTerms
              select s.term;

//all possible  results  
var results = from r in dc.Data
              select r.hyperlinks;

I want to perform an operation where I get all "r.hyperlinks" that contains s.term. It is something like r.hyperlinks.Contains(s.term). How can I do this?

+2  A: 

Hi! It's almost as you wrote it in english:

var results = from r in dc.Data
              where searchTerms.Any(x => r.hyperlinks.Contains(x))
              select r.hyperlinks;

That's all!

You can put any condition you might come up inside a where clause. Actually, you can put whatever returns a boolean.

Bruno Reis
I did that before and the code bombed.
Phil
What do you mean the code bombed? Did you define s?
David
Not everything that can be done in LINQ to objects can be done in LINQ to SQL. Ultimately the expression needs to be transformed to T-SQL. @Phil: Bombed? It would help if you include in your question the error you are getting.
AnthonyWJones
Updated to reflect OP's comment on his question.
Bruno Reis
By "bombed" I mean there was a syntax error. The error I get is: "Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator."
Phil
Does this last code give you a syntax error?
Bruno Reis
A: 

Local sequences cannot be used in many LinqToSql operators. But your original question didn't require a local sequence.

var results =
    from r in dc.Data
    where dc.SearchTerms.Any(s => r.hyperlinks.Contains(s.Term))
    select r.hyperlinks;
David B
Here is the error I get: "Only arguments that can be evaluated on the client are supported for the String.Contains method." Do not worry about it. I will just use stored proc.
Phil