score:1
var custlist = new hashset<string>() { "a", "b", "c"...};
from record in table.toenumerable()
where custlist.contains(record.field<string>("customerid"))
score:0
var custlist = new hashset<int> { 10, 15, 17 };
customerset.where(c => custlist.contains(c.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.
Source: stackoverflow.com
Related Query
- LINQ equivalent of SQL IsNull(..,..) in the Where Clause
- linq to dataset equivalent of SQL LIKE clause
- LINQ to Dataset - equivalent of sql (where ... in...)
- Linq union all equivalent of sql code
- Equivalent C# LINQ code for SQL
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- LINQ to SQL Where Clause Optional Criteria
- What is the linq equivalent to the SQL IN operator
- How are people unit testing code that uses Linq to SQL
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Equivalent of SQL Between Statement Using Linq or a Lambda expression
- linq to sql query with multiple where parameters
- Linq to SQL multiple conditional where clauses
- performance of LINQ queries against the SQL equivalent
- What is SQL equivalent to LINQ .All()
- LINQ to SQL - Why can't you use a WHERE after an ORDER BY?
- LINQ to Entities equivalent of sql "TOP(n) WITH TIES"
- LINQ WHERE method alters source collection
- Where to find translated Linq to Entity query to Sql
- Where can I view LINQ source code?
- LINQ to SQL - select where text like string array
- Linq to entities - SQL Query - Where list contains object with 2 properties (or more)
- How to Use Effeciently Where Clause or Select in LINQ Parallel in Large Dataset
- Dynamic Where Clause over relational tables with LINQ to SQL
- linq equivalent sql query "not in (select query)"
- Seemingly equivalent queries in LINQ and SQL returns different results
- 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 equivalent of 'select *' sql for generic function?
- Linq Query Where() SQL % equivalent
More Query from same tag
- LINQ query with date ranges
- "Grouping" dictionary by value
- Printing out the results of my linq query
- Linq Where Clause 'AND' 'OR'
- Why use LINQ Join on a simple one-many relationship?
- How to aggregate the value from DISTINCT row using LINQ
- Going all over a list and checking if boolean property are in the list
- When is data loaded into app server's memory?
- Fetch data using where clause
- Using ASP.Net, what would be the best control to use in this situation?
- Is this loop possible to do using simple LINQ?
- Does accessing MemoryCache create a copy?
- LINQ If .Any matches .Any
- LINQ query isn't applying order by
- Find address by latitude and longitude from a point (lat, lng) given
- how to retrieve data between two dates in linq
- linq update issue
- c# json count node's children
- Linq VAR and Typed Object
- Error while executing statement in ASP.NET MVC4 LINQ
- How can I apply paging to a non-list type
- I need closing ) parenthesis?
- Populating nested dictionary from database query c#
- How can I query by property type rather than type name using LINQ?
- C# Linq search inside object linked property
- Get value from anywhere in a text file
- LINQ Expression - Returning a UserID based on the Name Specified in a LinkLabel
- LINQ Join Errors
- Linq Distinct not bringing back the correct results
- How to insert data into 4 tables that have relationships using LINQ to sql