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 Articles
- How do I get results from a Linq query in the order of IDs that I provide?
- How to return query results from method that uses LINQ to SQL
- Linq query that return N results from two grouped columns
- linq query that joins results from three other queries
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- Linq to SQL - How to sort results from query
- How do I ignore/remove non-number values from linq query results C#
- Check if results from LINQ query contains a value
- Which LINQ query to select rows from 1 table that are not in another table
- 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 to use LINQ to query list of strings that do not contain substring entries from another list
- Creating multiple results from Linq query
- using linq query to find value that differs from previously found value
- LINQ query returns old results when source list is re-initialized
- Updating the original reference to an object that was returned from a linq query
- creating Linq to sqlite dbml from DbLinq source code
- C# LINQ : Dynamically create property and values that includes sum of a value from a grouped query
- LINQ Query limiting from - to results
- Populate Observable Collection from LINQ query results
- 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?
- Updating LINQ to SQL but the query i have is from a join? Can't update using query that uses a join?
- Creating a LINQ query that will include all entries from the current week excluding today and yestreday
- How to generate a LINQ query that queries all non-null properties from a search page model
- Exclude LINQ results from one query in another LINQ query
- mixing database and object query in linq and provide paged results
- EF Core Linq Query to Select Rows That Match From a List of Possibilities
- VB Linq Group Join query FAILS to order the results in descending order
- C# Linq XDoc - add element with same name
- How to get first row from DB using Entity Framework where column starts with certain string and continues with numeric characters
- Use dynamic linq or sql query in report generator
- how to convert T-SQL Query to linq
- Linq To NHibernate: .StartsWith on multiple properties
- Adding an element to an XML-document with a previously newly created string from an attribute node
- How to get input value of dynamically added textboxes
- GroupBy in lambda expressions
- Is an object still connected to a list after FirstOrDefault?
- How to change values of few properties from one list to another using LINQ C#:
- Using int.parse(string) in linq search doesn't work
- Linq Query Using Not In A Separate Table
- LINQ and Boolean Values
- C# - getting multiple data on combobox
- the sequence does not have elements executing linq query
- C# Entity Framework 4.1: include paths in query for loading related objects
- Add/Update IEnumerable List
- ASP/MVC3 Razor Linq
- Query for items per day
- Is this query being executed on an in-memory collection, or in the database?