开发者

In LINQ to SQL, how do you determine what column elements is a sub-set of another column (i.e. Like-Sql statement)

开发者 https://www.devze.com 2022-12-10 18:29 出处:网络
Here is some code: //all possible search terms of interest searchTerms = from s in dc.SearchTerms select s.term;

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.hyperl开发者_如何学编程inks.Contains(s.term). How can I do this?


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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消