Convert Linq Entity Query into T-SQL
Why Should We Convert ?
1. We all know we are better T-Sql professionals than quite new Entity framework.So by converting entity query into T-Sql we can understand the job we want to do by using Entity query is happening.
2. We can use generated T-Sql query to identify the Index Keys for tables which are needed for gain more performance.(as a input for Database Engine Tuning Adviser- my next blog-post will explain how to do)
3. By studying those generated T-Sql we can improve our Entity query for better performances (using SQL Server Execution Plans etc.).
How To Do That?
Method 1 :
You can use LINQPad.It's Free http://www.linqpad.net/
(Note: my next blog-post will explain how to configure LinqPad with Visual Studio )
Method 2 :
You can use SQL Server Profiler inside the Sql Server (Tools --> SQL Server Profiler)
Method 3 :
You can use Visual Studio Debugger for Generate T-Sql.(with any visual studio version)
Note: One thing I need to mention here is After request the data from Database Server by using FirstOrDefault() , ToList() ,etc then you cannot use above method.So you have to investigate T-Sql Before calling it to the Database server (the way I showed in above image).
Conclusion
You can use one of the above method to investigate the T-Sql generation from EF Query Without using High Paid 3rd party tools or Visual Studio Ultimate edition.
0 comments:
Post a Comment