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: " +
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
2.join 3.WHERE

 linq Detailed explanation