score:1
Accepted answer
I would just do it outside of the SQL query. There's really no benefit to getting it done on the SQL Server in this case.
var items = (from mytable in db.MyTable
where IDs.Contains(mytable.mytableID)
select mytable)
.ToArray()
.OrderBy(x => Array.IndexOf(ids, x.mytableID));
score:1
This should work with LINQ-to-objects; I'm not sure if it does with LINQ-to-SQL though:
var ids = new int [] { 5, 20, 10 };
var result = from item in items
where Array.IndexOf(ids, item.Id) >= 0
orderby Array.IndexOf(ids, item.Id)
select item;
Source: stackoverflow.com
Related Query
- How do I get results from a Linq query in the order of IDs that I provide?
- How to get a Linq query to order results based on the order of arguments in a method signature
- How to get the TSQL Query from LINQ DataContext.SubmitChanges()
- Get the "latest" datetime from a large linq query that currently returns every record that has a datetime
- Get the lowest year from LINQ query results
- How do you write a LINQ query that filters a sub table to a specific time period and sums the results of the sub table?
- How to return query results from method that uses LINQ to SQL
- How can I use Linq with JSON to get all the Ids from this odd JSON?
- How to get the generated Lucene query from a LINQ query
- How can I get the type of the results of a LINQ query before executing it?
- How to get this linq query to access info from the previous row
- How to get the list of class from the output of linq query
- how do i get the min from a linq to dataset query
- How can I simplify (speed up) the selecting query from a database that contains more than 1 million records using LINQ
- When running a method that uses linq to get the palindromes from a string, why does SelectMany order the resulting strings?
- how to get the linq list having Ids from IEnumerable<Object>
- How to group my LINQ query so that I get the desired result?
- How to get results from another query list if first linq query returns empty?
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- How to get the latest date inserted from the table with Linq to entities
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- Linq to SQL - How to sort results from query
- linq query to join two tables and get the count from one table values from the other
- How do I ignore/remove non-number values from linq query results C#
- Using LINQ to get the results from another LINQ collection
- How does linq actually execute the code to retrieve data from the data source?
- How to use Func in a linq query that provide an IQueryable output
- linq - how do you do a query for items in one query source that are not in another one?
- How can I write the following code more elegantly using LINQ query syntax?
- How to use LINQ to query list of strings that do not contain substring entries from another list
More Query from same tag
- LINQ with string variable for sorting
- Using interfaces in LINQ database queries
- Bug with the dmbl designer file under VS2008?
- LINQ to SQL: "Method 'Boolean Contains(System.String)' has no supported translation to SQL."
- How to convert GetFuncType using LINQBridge
- filter child entities while fetching a parent entity EF Core
- convert foreach loop to linq
- dictionary array value search using lambda
- Cannot get Linq syntax to work
- Count cells of a DataGridView with the same value and display the result
- Cut list using LINQ
- Ignoring case in Linq.Any, C#
- Imroving/Modifying LINQ query
- Pull all duplicate keys from list of key value pairs
- How to create optimal query?
- Ordering within groups using LINQ
- ASP.NET ReportViewer and Linq To Sql Questions
- Querying an ICollection in ViewModel
- dynamic sort columns doesn't work in linq
- C# Using LINQ Query compare the records with result of process array
- lambda expression with nullable value - always false since the value of type Guid is never equal to 'null'
- HtmlAgilityPack-PCL + LINQ
- In LINQ, can I select multiple items?
- filtering objects from List with foreach
- How to use a Factory method as resultSelector in LINQ Join
- Bind linq data to dropdownlist
- Linq to sort lists of different kind
- Implementing Bind() (SelectMany in LINQ) without yield (in C++)
- NUnit CollectionAssert.AreEqual(expected,actual) vs Assert.IsTrue(expected.SequenceEqual(actual))
- How to fill object with list using EF