score:0
I would use Enumerable<T>.All()
:
results = results.Where(d => d["FilterIDs" != null &&
d["FilterIDs"].ToString()
.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(Int32.Parse)
.All(f => filterValues.Contains(f)));
score:0
How about this?
results =
results.Where(
d => !d.IsNull("FilterIDs") && // Check the row has FilterIds
d["FilterIDs"]
.ToString()
.Split(',') // Tokenise the string
.Where(s=>!String.IsNullOrEmpty(s))
.ConvertAll<int>(s => Convert.ToInt32(s))
.All(i => filterValues.Contains(i) )
);
score:2
It seems that you have just reversed your Except
call - you have used A.Except(B)
when you mean B.Except(A)
.
That said, here's how I would write this:
var query = from row in results
let filterIds = row["FilterIDs"]
where filterIds != null
let numbers = filterIds.ToString()
.Split(',')
.Where(s => !string.IsNullOrEmpty(s))
.Select(int.Parse)
where !numbers.Except(filterValues).Any()
select row;
Source: stackoverflow.com
Related Articles
- select where all values present in List<int>
- In LINQ, select all values of property X where X != null
- Fluent LINQ - Select a list of parents that contains a list of children where a subset of children are present
- Linq Select with Where based on Dropdown values
- Select only the values present multiple times in a list C# Linq
- LINQ select from table where fieldValue is in another tables list of values
- How to specify where and select in a query containing ThenInclude, when either of where/select is not present in the query context?
- C# DataTable Linq select distinct values where column equals 'x'
- Using a Linq query to select objects where any value of a property matches values from a list
- MongoDB linq C# select document where array of subdocumnets contain all values from string array
- LINQ query to conditionally filter on a where clause and select the values from another table
- Select only those values from object where element occurs one time
- Select entries where only a Foreign Key is present for that ID
- Linq select objects in list where exists IN (A,B,C)
- Linq: What is the difference between Select and Where
- Why are Where and Select outperforming just Select?
- Linq code to select one item
- LINQ: Select where object does not contain items from list
- How to select values within a provided index range from a List using LINQ
- Filtering Null values in Select
- How to SELECT WHERE NOT EXIST using LINQ?
- Difference between Select and Where in Entity Framework
- Select All distinct values in a column using LINQ
- How to Select Min and Max date values in Linq Query
- How to select multiple values from a Dictionary using Linq as simple as possible
- How to select array index after Where clause using Linq?
- lambda expression join multiple tables with select and where clause
- Linq to Select Parent Objects Where Child Objects Have a Matching Child Object
- C# LINQ select from where value is not contained in array / list
- Select only the lowest values with Linq
- linq equivalent sql query "not in (select query)"
- IComparer, OrderBy and Linq
- Linq Count Group on List<List<string>>
- LINQ .Take() returns more elements than requested
- Linq - Aggregate strings with quotes
- C# exclude duplicate code from two method returning expression
- Group By object within a nested list linq
- Stop LINQ to SQL from executing select statements after insert
- If condition in LINQ Where clause
- Linq set a property in a list?
- List reference issue c#
- LINQ multiple joins with multiple conditions
- How can I filter nested items of IQueryable<T>?
- LINQ query, using relationships
- How to use CTE in Linq C#?
- Converting SQL group by and order by to Linq using case
- Getting wrong sum and count in linq
- Linq syntax method group by and subquery
- Filtering data with Expression Func - C# - How to apply filter on referent table?
- How to get the Latest DATETIME in my collection