UPDATE: I’ve cleaned up the code a bit and put it up on CodePlex at http://ordertolist.codeplex.com/ A team member recently wanted LINQ-to-SQL to perform a query with a Contains() clause and return the results in the same order. For example, he was passed a list of People: 1: List<int> idsOfPeopleToDisplay = new List<int> { 578, 291, 788, 230, 45 };
and he wanted to select all People from the database with those IDs, in that order. The following will result in a non-correctly ordered...
LINQ-to-SQL DataContexts have a boolean property called ObjectTracking which is used to determine whether the framework should exert the overhead necessary to remember previous states. This defaults to true and is used to determine the SQL UPDATE command to run when persisting the object. We have a project with data that’s read-only and so we decided to turn ObjectTracking off (set to false). We figured this was a good idea since, the thinking went, it would save overhead and since we’re not persisting the data anyway (read-only) we’ll have nothing to worry about. Boy were we wrong. All...