score:15
Yes, you use Contains
:
db.Products.Where(product => myFields.Contains(product.Category))
aka
from product in db.Products
where myFields.Contains(product.Category)
select product
score:0
In theory you would use contains:
var productList = from product in context.Products
where myfields.contains(product.category)
select product
However you'll need to test this - I seem to recall there being a bug in the Linq2Sql optimizer when trying to deal with List<> and array values being used like this (it may have only occured if you tried to cast them as IQueryable)
score:1
As other have mentioned, yes it does using the .Contains method. To benefit the other random people that may arrive here via Bing (or any of the other search engines): Linq-To-Entities does not support the .Contains method in the current version. However, with a simple extension method, you can do so:
http://george.tsiokos.com/posts/2007/11/30/linq-where-x-in/
Source: stackoverflow.com
Related Query
- Does LINQ to SQL support the t-sql "in" statement
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- How does the following LINQ statement work?
- The data source does not support server-side data paging
- What is the easiest way to find the LINQ statement for a SQL statement
- Does this LINQ code perform multiple lookups on the original data?
- Why does an IF Statement effect the outcome of my LINQ Statement?
- How does linq actually execute the code to retrieve data from the data source?
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- Does LINQ To SQL auto update the LOCAL/CLIENT id column after a SubmitChanges call?
- How to code the partial extensions that Linq to SQL autogenerates?
- Determine the source DataContext for a Linq to Sql query
- How to know which Linq statement produced the SQL on hand during runtime?
- When selected into an object; does Linq To SQL still perform the logic in a SQL Query?
- Where does this Linq statement get the selected value from?
- Does LINQ convert code to SQL queries
- Why the default that i see in SQL Server for the fields does no reflected in LINQ
- How do I write a LINQ to SQL statement with a custom function that needs the compare the current item context to a passed in value?
- Why does my LINQ to SQL query fail the first time ("Row Not Found or Changed") and succeed the second time?
- LINQ to SQL With the where with case statement
- Why does LINQ generated SQL include multiple "IS NULL" conditions for the same column
- Linq to SQL FirstOrDefault does not execute the SQL query
- Does using a LINQ statement in a foreach re-evaluate the statement on each iteration
- How to write the SQL ORDER BY {value} DESC LIMIT statement in LINQ to Entities (Entity Framewok)?
- What SQL query or LINQ code would get the following data?
- The required column 'int_CommodityPriceId' does not exist in the results. linq to sql
- Getting Last rows from the result of Linq to Sql statement
- SQLite DB: Create a SQL Statement with LINQ that uses the same table twice but without CROSS JOIN
- SQL issue- statement returning the same even though trying to sort the fielld using where - nested query - convert to LINQ
- Why does this LINQ left join statement compile down to an SQL statement with a sub-query in EF 6?
More Query from same tag
- Implementation for a method that finds the first nonrepeatable character in a string using Linq, while crossing through the string only once
- Select all users that have commented post in ASP.NET MVC
- Retrieve properties from List(T), any options besides FOR EACH
- c# Linq: Replace empty string with some value
- Using LINQ to create pairs from two different list where the entries have same attribute
- Generate all possible coverage options
- linq sum string as decimal
- How to access a table in linq
- Select data from multiple unrelated tables with LINQ to Entity Framework
- how to generate where condition without multiple if condition using linq query
- Combining multiple dictionary where key matches
- Group by array contents
- Linq Expression tree Any() issue
- Get Average of column using group by
- How to Implement linq on dictionary in C#?
- Linq, force an item to be first?
- Adding an artificial row to an anonymous Linq resultset
- How can i compare and seach string and datetime c#
- LINQ to Entity Query - duplicates in a group
- Linq to SQL to DataGridView
- C# linq query rank by two conditions
- linq query with dynamic predicates in where clause joined by OR
- Entity Framework Core SaveChanges doesn't update records
- XDocument.Descendants returning null values
- Linq Query with date range not returning any records?
- Linq Paging - How to incorporate total record count
- cannot implicitly convert type 'system.collections.generic.list<system.linq.igrouping<int, yyy>>' to 'system.collections.generic.list<yyy>>
- Reading master and child tables from a combined table
- Most efficient way to search enumerable
- LINQ to handle IEnumerable and remove unmatch items from sub entity