score:1
var custList = new HashSet<string>() { "a", "b", "c"...};
from record in table.ToEnumerable()
where custList.Contains(record.Field<string>("customerID"))
score:2
In LINQ you use the Contains()
method to perform these kind of queries.
I don't know LINQ to DataSets, but in LINQ to SQL you can do the following:
var statuses = new int[] {1, 2, 3};
var query = from p in dataContext.Products
where statuses.Contains(p.Id)
select p;
This should generate SQL similar to:
select * from Product p
where p.Id in (1, 2, 3)
(Note how it feels back-to-front in the LINQ code to the generated SQL - that's why if you know SQL well it's not very intuitive, but it makes very elegant use of existing .NET language features)
This also typically works for string
and collections of some other basic types that L2S knows about because they're in the framework.
score:0
var custList = new HashSet<int> { 10, 15, 17 };
CustomerSet.Where(c => custList.Contains(c.CustomerID));
Source: stackoverflow.com
Related Articles
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- LINQ WHERE method alters source collection
- Where can I view LINQ source code?
- How to Use Effeciently Where Clause or Select in LINQ Parallel in Large Dataset
- LINQ Source Code Available
- LINQ WHERE clause equivalent in javascript
- Linq with where clause in many-to-many EF Code First object
- LINQ equivalent of SQL IsNull(..,..) in the Where Clause
- How to render this map-reduce javascript code to an equivalent LINQ Select-Aggregate?
- C# - Linq optimize code with List and Where clause
- creating Linq to sqlite dbml from DbLinq source code
- linq to dataset equivalent of SQL LIKE clause
- LINQ to Dataset - equivalent of sql (where ... in...)
- Linq union all equivalent of sql code
- C# code for equivalent LINQ query
- How can I code numerous MIN functions into one LINQ to DataSet query
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- how to write LINQ to objects equivalent code for this code
- source code for LINQ 101 samples
- Linq extension method equivalent for that code in VB.NET
- LINQ where clause using Generic IQueryable source
- Linq Equivalent to Where Clause with Nested Conditions
- LINQ equivalent of WHERE IN clause
- Equivalent C# LINQ code for SQL
- How to replace lambda written in Where clause of Linq with equivalent delegate
- LINQ equivalent to SELECT WHERE xx IN (col1, col2, ...)
- Linq JOIN on a strongly typed dataset where comparator contains DbNull throws exception
- c# Linq or code to extract groups from a single list of source data
- Entity Framework dynamic linq where from generic source with dynamic where clause
- Filter Products in a Dynamic Way using LINQ
- LINQ query nested list?
- Converting a LINQ result to 2D string array
- How can I reduce a list by or-ing all its elements together?
- LINQ query to include fields from one row of a child table
- is there a better way to order a IEnumerable to match an arbitrary ordering?
- linq check what condition return false in multiple and-conditions
- Linq: How to group by maximum number of items
- EF 4.1 POCO query
- Get data from relationship objects in entity framework?
- How to convert List<ICollection<Patients>> to IEnumerable<Patients>
- Grouping and SUM with LINQ (on conditions)
- LINQ Group by error: "does not contain a definition for 'GroupBy'"
- LINQ Nested Condition
- Compare object in custom list and return the unmatched object C#
- How to pass the current index iteration inside a select new MyObject
- Get distinct dates in datatable
- Exists query with LINQ
- Requires a model item of type 'System.Collections.Generic.IEnumerable`1
- LINQ , How to get Max ID with "where" condition