What you have is correct. This will be translated into an
IN clause in SQL with the values supplied in the collection.
On an unrelated note, you should try ordering the query by date descending and use
FirstOrDefault(). As it is now, you're going to bring back the entire result set and throw away every row but one.
This will translate into efficient SQL, so there's no need to use anything else.
You should be careful with such queries with
list.Contains() inside of
linq query. Because for each list element it will create a param in
And there's a limited number of params allowed in sql statement,
So if your TheIDs will contains more than
2100 elements it will fail.
If you want to use in this way, you should at least check your TheIDs
count and if more then
2100 dived it in pieces with less then
- Using Linq to do a Contains with multiple values
- Determine, that sequence contains other sequence, in same order, with using LINQ
- How can I select using LINQ for an entry that contains a LIST with more than one row?
- Linq sub query when using a repository pattern with EF code first
- Entity Framework with LINQ using CONTAINS in WHERE clause very slow with large integer list
- Can't add a new record with an integer value into database by using linq from code C#
- The source contains no DataRows using Linq
- Using Linq to select from a List in a List with Contains
- Nested LINQ query using Contains with a bigint
- Compiling Error with LINQ Sorting Code Using List<T>
- trying to write a LINQ query using contains and starts with from a List
- I need to save the XML file using linq with xml code in C#
- C# Dynamic Linq Query with Fluent Mongo - Without using Contains or PredicateBuilder
- Using linq with Contains - getting error
- WPF: How do I fill a datagrid with NWS XML Data that contains Attributes with spaces using LINQ
- EF code first: using Linq with many-to-many relationship
- Using LINQ and contains with comma separated values
- Error when using Contains within linq query with results from another query
- How to select only string records with contains conditions using Linq
- LINQ using Contains with entity
- How to call an Sql User defined Function using Entity frame work Code first approach with LInq c#
- NullReference exception when using LINQ Contains with Entity Framework
- Convert string to int in one line of code using LINQ
- Using IQueryable with Linq
- Determine if a sequence contains all elements of another sequence using Linq
- Error: "The specified LINQ expression contains references to queries that are associated with different contexts"
- Sequence contains no elements exception in linq without even using Single
- Populate a list with a specific range of numbers by using LINQ
- How to handle NULL object property with FirstOrDefault using Linq
- Determine sequence contains no element using LINQ
- LINQ to DataTable Easy and Fast
- Linq-to-SQL and Performance
- C# Compare two strongly typed list
- How to get the date difference by joining two tables?
- Duplicated output when counting chars in a string with Linq
- How to add an in command to a where clause in LINQ?
- All array slots contains last result
- LINQ query succeeding/error depends on one arbitrary assignment statement
- Flatten xml with text and element nodes using LINQ to XML
- How can I remove all ListItems except the one having a particular value from an ItemList of a drop-down?
- Getting The query contains references do Elements defined in the context of other data Error
- Async await in linq select
- Combining Linq Queries with ANDs or Ors
- How to use dynamic OrderBy variable with anonymous type?
- How to get highest value from xml element in C#?
- without for loop how can is show var type these value in TextBox
- Create DetailList of Group By LINQ
- C# Grouping in LINQ with sum of certain fields
- MVC3 Linq updating two tables with data from one model
- LINQ to find series of consecutive numbers