Tip: Be careful when making quires using LINQ
If you’re using LINQ just be careful when you are using functions or properties while comparing the data
For example if you have a date field and you want to get today items, if you use the following code
var result = from item in listofitems where item.Date == DateTime.Today select item;
This code it will take very much long time of the following code
DateTime today = DateTime.Today;
var result = from item in listofitems where item.Date == today select item;
I test the first code with around 5,000,000 items, it takes 2.684 seconds but the 2nd one It takes 0.302 of the second, so that means if you put a function or other property which is takes 1 millisecond, it means your query will take 1 second for checking 1000 item which is no need for this time, instead just save the result of the function or property before doing the query, save it in a variable and then pass it to the query, as I did in the second code.


