'I have an IQueryable with WHERE IN (ids). Can ToList() return the same order as ids?

My code:

var ids = new int[] { 16259,16238,16240,16243 };
var teamQuery = _teamRepository.Where(team => ids.Contains(team.ID));
var teams = teamQuery.ToList();

I have a IQueryable object teamQuery which forms a query

SELECT
    [Extent1].[ID] AS [ID],
    [Extent1].[Name] AS [Name],
    FROM [dbo].[Team] AS [Extent1]
    WHERE [Extent1].[ID] IN (16259, 16238, 16240, 16243)

Can I keep the same order in the generated List teams object during ToList() materialization as in the IN method (16259, 16238, 16240, 16243)?

Now the order of objects in teams is [16238, 16240, 16243, 16259]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source