score:2
Accepted answer
from p in Products
where new int [] { 2,6,9 }.Contains(p.ProductID)
select p;
score:1
var q = from p in Products
where p.productID==2 || p.productID==6 || p.productID==9
select p;
foreach(var product in q)
{
//...
}
or simply:
db.Products.Where(p=> p.productID==2 || p.productID==6 || p.productID==9)
Source: stackoverflow.com
Related Query
- Need to debug LINQ simple queries in Visual Studio 2010
- LINQ Source Code Available
- Need simple example of WPF binding Objects to Listbox with LINQ
- creating Linq to sqlite dbml from DbLinq source code
- Need a LINQ code example to link two tables that have no foreign key
- need a simple linq
- My code is very inefficient for this simple Linq usage
- source code for LINQ 101 samples
- I need to save the XML file using linq with xml code in C#
- Need help with a simple Linq query running with Entity Framework 4
- Simple linq question: How to filter a source afterwards?
- c# Linq or code to extract groups from a single list of source data
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- Simple LINQ and List error: WhereListIterator`1[Task]' to type 'System.Collections.Generic.List`1[Task]'
- How to select multiple values from a Dictionary using Linq as simple as possible
- Running a simple LINQ query in parallel
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Why use LINQ Join on a simple one-many relationship?
- Row not found or changed LINQ C# error on simple statement
- Convert simple SQL group-by into LINQ to SQL
- LINQ Query problem. Need to check if exists
- Syntax to execute code block inside Linq query?
- Why do I need Stored Procedures when I have LINQ to SQL
- simple select query in linq
- Why am I required to reference System.Numerics with this simple LINQ expression?
- Simple way to update IEnumerable objects using LINQ
- Simple sql to Linq query with group by and aggregate functions
More Query from same tag
- LINQ to entities - left join with condition
- Expression.Like alternative for filtering based on text in c#
- Why is my linq alias out of scope?
- How to add OrderBy clause in multi-table LINQ query?
- How can you eliminate variable declaration in LINQ query syntax foreach?
- Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource
- Reactive Extensions clean up
- LINQ get objects by date interval
- LINQ Lambda Left join with an Inner join
- Is it possible to change replace datasource Dynamically in LINQ?
- Is this query being executed on an in-memory collection, or in the database?
- How to convert/cast IQueryable<AnonymousType> to IQueriable<Strong Typed Object> with lambda expressions
- how can combine multi table with same columns in one common view model
- SELECT result map to entity in Dynamic Linq in Entity Framework Core
- How do I print different names from a list?
- Converting Stored Proc to LINQ to Entities
- How can i look at query LINQ
- DbSortClause expressions must have a type that is order comparable. Parameter name: key
- How to use Linq to join entity tables with a cross-reference table
- Check if a table contains overlapping timespans
- Compare dates linq c#
- Linq return first date
- LINQ: grouping based on property in sublist
- Getting Attribute Inside Linq "Where" using string
- LINQ - To Get Year from Date which is of Type String
- How to return rows in LINQ and MVC ,
- Convert object[] into Lookup with Linq
- winforms datagridview sorting using LINQ
- Fastest way to build hierarchical structure
- Query first element in all columns in a jagged array