describe : It is used in the project linq, It is found that the order of writing is different, and the final result is also different , The efficiency is not the same .

Linq Comparison of execution efficiency of
List<int> source = new List<int>(); var rand = new Random(); int i = 5000;
while (i > 0) { i--; source.Add(rand.Next(1, 500)); } Stopwatch watch = new
Stopwatch(); watch.Restart();var temp2 = from s in source orderby s where s >
100 select s; int count2 = temp2.Count(); watch.Stop(); Console.WriteLine("
orderby s where s > 100:" + watch.ElapsedTicks); watch.Restart(); var temp1 =
from s in source where s > 100 orderby s select s; int count = temp1.Count();
watch.Stop(); Console.WriteLine("where s > 100 orderby s: " +
watch.ElapsedTicks);
The effect is shown in the figure :



The efficiency difference is quite large , almost 10 times , therefore linq To be executed in a certain order , You can't do what you want .

Linq optimization

linq and sql The grammar is similar , So you can follow the sql The execution sequence of linq Optimize , Suggested order
1.FROM
2.join 3.WHERE
4.GROUP BY

5.ORDER BY 6.SELECT
 linq Detailed explanation

https://www.cnblogs.com/zhao123/p/5621841.html