Introduction
This is a series articles of ASP.NET Tips and Tricks. Under my previous article Common ASP.Net Tips and Tricks Part 1, we learned configuration tips and tricks. The article explained common exceptions we encounter while development and best practices for code implementation.
Tips and Tricks
LINQ to Entities does not recognize ToString
Sometimes LINQ to Entities does not recognize the method "System.String ToString()" and this method cannot be translated into a store expression.
Solution
This type of exception frequently occurs when we are working with LINQ or EntityFramework.
For example:
Solution
This type of exception frequently occurs when we are working with LINQ or EntityFramework.
For example:
- var result=dc.Tests.Where(i=>i.status==status.ToString()).FirstOrDefault();
According to the preceding syntax, when we convert “status.ToString()”, in the where condition the exception "Expression not found such method in SQL" occurs where the condition returns an IQueryable result. So if we convert the result to IEnumerable, then the preceding type of exception never occurs.
For example:
For example:
- var result=dc.Tests. AsEnumerable().Where(i=>i.status==status.ToString()).FirstOrDefault();
ToString() vs Convert.ToString()
Which is best, ToString() or Convert.ToString()?
Solution
Always use Convert.ToString() conversion for strings since it handles null values also, whereas ToString() leads to an exception when we convert a string from null.
string or StringBuilder
Solution
Always use Convert.ToString() conversion for strings since it handles null values also, whereas ToString() leads to an exception when we convert a string from null.
string or StringBuilder
What to use, string or StringBuilder, for string manipulation?
Solution
Always use StringBuilder that stores a string for manipulation or appends a string to it. Whereas each string concatenation leads to copying a string to another string variable instead of preserving one memory allocation.
If(isBool==true) vs if(isBool)
Solution
Always use StringBuilder that stores a string for manipulation or appends a string to it. Whereas each string concatenation leads to copying a string to another string variable instead of preserving one memory allocation.
If(isBool==true) vs if(isBool)

SubashPosted Aug 23, 2016, 12:39 AM
Great tips
Vaikesh K PPosted Sep 29, 2015, 7:56 AM
Nice
Ano MepaniPosted Jun 28, 2015, 6:54 AM
Thank you all
Khan Abrar AhmedPosted Jun 28, 2015, 6:01 AM
Nice one
Santhakumar MunuswamyPosted Jun 27, 2015, 10:54 AM
Thanks for nice article:)
Rajeesh MenothPosted Jun 27, 2015, 8:30 AM
NIce One,Good Arvind Mepani
Pankaj Kumar ChoudharyPosted Jun 27, 2015, 12:46 AM
Nice Information Sir............
Sibeesh VenuPosted Jun 27, 2015, 12:32 AM
Good one.
Ano MepaniPosted Jun 26, 2015, 2:40 PM
thank you rahul
Rahul PrajapatPosted Jun 26, 2015, 11:55 AM
Nice article , thanks for this information