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 Articles
- Does LINQ to SQL support the t-sql "in" statement
- How does the following LINQ statement work?
- The data source does not support server-side data paging
- Does LINQ natively support splitting a collection in two?
- Does NHibernate LINQ support ToLower() in Where() clauses?
- Linq to Entities Group By (OUTER APPLY) "oracle 11.2.0.3.0 does not support apply"
- How does LINQ defer execution when in a using statement
- Why does EF 5.0 not support this EF 4.x LINQ syntax when compiling to sql?
- LINQ to Entities does not support extension method?
- 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?
- LINQ Source Code Available
- How does this linq code that splits a sequence work?
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- Does .Net Core 2.1 Support LINQ and Lambda Expressions?
- Does LINQ Support Composable "OR Queries"?
- Does C# linq support "anti join" semantics?
- creating Linq to sqlite dbml from DbLinq source code
- Where does this Linq statement get the selected value from?
- Does LINQ convert code to SQL queries
- What kind of object does a linq statement return?
- why does this linq code get exponentially slower when applying First() to projection?
- Convert code that uses Linq to code that does not
- Why does this LINQ statement throw a timeout error?
- source code for LINQ 101 samples
- How to write a LINQ If Else statement that does not return any value(even a null) if check evaluates to false?
- Does using a LINQ statement in a foreach re-evaluate the statement on each iteration
- How to do condition statement in LINQ based on code variables?
- LINQ to Entities Does not Support Invoke in Entity Framework
- Getting a single result from a LINQ statement
- lambda expression to verify list is correctly ordered
- Finding list of serial devices using LINQ
- Need help with Linq
- How do I access columns from joined tables using Linq, C# in asp.net MVC
- SQL Query inner join in Linq
- linq to sql - Handle empty column of type XML
- C# Visual Studio: How do I update a DB from Edit with DataGridView using LINQ?
- Additional information: LINQ to Entities does not recognize the method and this method cannot be translated into a store expression
- Cannot select most recent ticket from a collection of tickets
- Many to Many relationship using SQL and Linq (entity framework/to entities)
- Inserting a value from a drop down list to UserProfile Table while registering a user
- Compare same DataTable by certain columns, return mismatches to CopyToDataTable()
- how to add the number of items at the end of the linq query
- Implementation for a method that finds the first nonrepeatable character in a string using Linq, while crossing through the string only once
- IN Clause from an included table, doesn't works as expected
- Angular js can't fetching data from ASP.Net Identity default user table
- C# get minute number from date in linq group by
- Collection was modified; enumeration operation may not execute , even when i create a copy of the current object
- Weird nullable comparison behavior