score:0
I figured it out. Since I can't use the Any
keyword, I used this function:
public static bool ContainsAny(this string databaseString, List<string> stringList)
{
if (databaseString == null)
{
return false;
}
foreach (string s in stringList)
{
if (databaseString.Contains(s))
{
return true;
}
}
return false;
}
So then I can use this expression in my Where
clause:
expression = i => i.Domains.ContainsAny(_mainDomains);
Update: According to usr, the query would return all the values and execute the where clause server side. A better solution would be to use a different approach (and not use stuffed/comma-separated values)
score:3
You can use contains:
where i.Domains.Any(s => _mainDomains.Contains<string>(s.xxx))
Notice that the generic arguments are required (even if Resharper might tell you they are not). They are required to select Enumerable.Contains
, not List.Contains
. The latter one is not translatable (which I consider an error in the L2S product design).
(I might not have gotten the query exactly right for your data model. Please just adapt it to your needs).
Source: stackoverflow.com
Related Query
- LINQ to SQL where clause verifying string contains list element
- EF LINQ to SQL is getting whole table from DB instead of selection - where clause contains list with Any statement
- LINQ Where clause with Contains where the list has complex object
- Linq to entities - SQL Query - Where list contains object with 2 properties (or more)
- C# - Linq optimize code with List and Where clause
- Linq - How to apply a where clause on the maximum element of a list
- LINQ Where clause throws casting exception from string to Guid even though comparison only contains Guids
- Entity Framework with LINQ using CONTAINS in WHERE clause very slow with large integer list
- Issue with adding Linq Where clause containing a string Contains test
- LINQ - Where a string contains any element in an array
- Expressing IN sql statement in Linq with computed string in where clause
- How to use Linq where condition to check if a list of strings contains any string
- LINQ - Where a list contains an element of another list
- LINQ select item from a list where string contains any of the search terms in a list -> refactor
- Linq to SQL string concatenation where clause generates buggy sql
- Check if list contains element that contains a string and get that element
- linq where list contains any in list
- LINQ to SQL Where Clause Optional Criteria
- Linq filter List<string> where it contains a string value from another List<string>
- Check if a string within a list contains a specific string with Linq
- How to use Linq to check if a list of strings contains any string in a list
- Checking if list of Tuple contains a tuple where Item1 = x using Linq
- Where clause in Linq in List c#
- LINQ select List where sub-list contains item from another list
- C# predicate list passed to Linq Where clause
- LINQ to SQL - select where text like string array
- Dynamic Where Clause over relational tables with LINQ to SQL
- Expression to get LINQ with Contains to EF for SQL IN() where on entities child's property equals value
- Linq to SQL: Where clause comparing a Nullable<DateTime> with a SQL datetime null column
- linq where contains ALL items in list
More Query from same tag
- Filter a List with linq
- LINQ sorting on objects on subobject
- GroupBy by many different keys
- Include many to one records in LINQ
- List<int> separated into thirds
- XDocument XElement.Descendants issue
- Why use wrappers around the actual iterator functions in LINQ extension methods?
- Get a column list of values in LINQ
- In LINQ to Entities, How can you order like follows?
- Linq DateTime expressions wont compare if only one is nullable
- Convert .Net LINQ Query to Angular 2 TypeScript / JavaScript
- Add a LINQ or DBContext extension method to get an element if not exist then create with data in predicate (FirstOrCreate)
- categories and sub-categories in c# / linq & sql
- Linq All on empty collection
- Linq Join using bit mask logic
- Issue with Simultaneous users making changes in a databound DataGridView
- Fastest way to get values from 2d array
- Linq Group By - select a single record in each group into typed result
- testing for no return from LINQ
- Linq to sql order by a string that is not a property of the object
- LINQ - exclude the filter when the value is NULL
- How to properly use LINQ Query on List<KeyValuePair<string, string> to create Dictionary<KeyValuePair<string, string>, int>?
- Linq Nhibernate : Unable to pull a value from a foreign key table
- WinForms Data Binding Entity Framework 6
- Cast an object to IEnumerable<T> where I know what T is
- Add count/sub-count to mvc view
- LINQ Sum Query on a Child element
- Python LINQ like methods
- How do I pass an Entity Object to a function in C#
- ASP.NET MVC Recursion Procedure