score:6
Accepted answer
entities.newinstance.subjects.where(x => alreadyselectedids.contains(x.id)).tolist();
should work, if alreadyselectedis
is not null
you can do a null check inside or before your query :
entities.newinstance.subjects.where(x => alreadyselectedids == null
? true // or false
: alreadyselectedids.contains(x.id)
).tolist();
(which can be rewritten, depending if you want all or nothing if alreadyselectedids
is null)
//return all if null
x => alreadyselectedids == null || alreadyselectedids.contains(x.id)
or
//return nothing if null
x => alreadyselectedids != null && alrreadyselectedids.contains(x.id)
Source: stackoverflow.com
Related Query
- IQueryable for entities .Where( property is in local array)
- Expression to get LINQ with Contains to EF for SQL IN() where on entities child's property equals value
- linq remove item from object array where property equals value
- Check Contains into an int array for null property
- Building a dynamic where clause for dynamic keywords or using IQueryable C# Linq
- Select entities where ID in int array - WCF Data Services, LINQ
- Internal access for entities in Entity Framework makes simple linq where query crash
- Where is the source for System.Linq.Enumerable.ToList()?
- Where is the code for the EDML generated Models?
- Filtering an array of objects to remove the ones that don't have the greatest value of for a property
- Searching for a text in a string property where the value is HTML
- .NET LINQ to Entities base where clause for generic Type
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- LINQ to JSON - Select array object element where specific property matches
- Query all the entities where list property contains everything in another list
- Task Does Not Contain a Definition for Where If Done in One Line of Code
- Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique?
- JAVA What is the most optimal way to call Object array methode where property is equal to a string?
- 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?
- Linq to Entities where clause on navigation property
- Linq to Entities add Where clause for EXISTS lookup in another table
- Create an iQueryable which is case insensitive for unit testing linq to entities - NSubstitute
- source code for LINQ 101 samples
- How to use "All" for an array property in a class using MongoDB C# Driver?
- Creating a dynamic EF filter that builds a LINQ Where equals/contains statement for any string entity property
- Create a Linq to entities IQueryable extension for date grouping (GroupBy)
- LINQ where clause using Generic IQueryable source
- C# linq query with where subquery for each property
- Custom expression for RavenDB where clause: field contains any item from provided array
- Reversing IQueryable based on passed property for sorting logic
More Query from same tag
- How dynamically group by and compute aggregate sums/maximums data with LINQ in c#
- LINQ Optimization Question
- Cannot implicitly convert type 'DateTime' to 'bool' linq query
- How can I add a DisplayMember and ValueMember to a single ComboBox Item that has an assigned DataSource?
- List and create in same view in asp.net mvc
- What is the lambda equivalent of this Linq query?
- LINQ DynamicLibrary: How to extract count and list from IQueryable
- Querying complex data types in EF Core with LINQ
- Error in filtering Sql returns direct cast error
- Retrieve list of class from DB using Entity Framework filtered by a computed property?
- How can I return the contents of a collection inside a class using LINQ?
- how to practically assign repeating objects from groups
- Simple LINQ select (using Entity Framework) does not return values
- How to make a SUM of Dictionary Value nested into a list with LINQ?
- IEnumerable takes too long to process when filtering on it
- Load most recent related entity record on a list of entities in a single query
- LINQ Parsing XML
- Linq .ForEach Optimization
- How to write Inline If Statement(SQL IIF) in EFCore Select?
- LINQ: several DeleteOnSubmit order behaviour on SubmitChanges
- LINQ order-by issue
- How to extract month from date time feild?
- How to dynamically populate XElement (linq to xml)
- LINQ: Problem using DB with relations
- The LINQ expression could not be translated. Eiither rewrite the query in a form that can be translated
- How to return a date or an error? c# .Net
- I wants to date month and year add 2 month later in linq
- LINQ causing my obfuscator to break
- I have an array, I want to find some element
- order by List of Guids position