c# - How to do a simple OR query with LINQ? -



c# - How to do a simple OR query with LINQ? -

i using linq entities , i'm trying simple or query. have table called "links" , when run query want include links containing tag list of tags , links matching search term. example:

var tags = new list<string> { "games", "events", "recipes" }; var searchterms = new list<string> { "hockey", "barbecue", "cheesecake", "basketball" } var links = _entitycontainer.links .where(x => x.tags.any(y => tags.contains(y.name)) .where(x => searchterms.any(y => x.title.contains(y)));

note: link entity has navigation property called tags in first .where() i'm checking each of tags in link's collection see if list of tags i'm searching contains 1 of them.

in sec .where() i'm checking if link's title property contains of search terms.

my problem code includes links contain @ to the lowest degree 1 tag list , match 1 of search terms. want include both together. want links list include links either match 1 or more tags in list or match 1 or more search terms in list.

i have issue because of tags.contains() , searchterms.any() because these calls cannot converted expressions passed ef. work if did tolist() cannot pull big number of records memory.

any suggestions accomplishing goal? help much appreciated.

condense 1 clause:

var links = _entitycontainer.links .where(x => x.tags.any(y => tags.contains(y.name)) || searchterms.any(y => x.title.contains(y)));

c# .net linq entity-framework linq-to-entities

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -