I know about Scott Gu's LINQ to SQL visualiser, but is there a way to take a LINQ expression at run-time and do something to find out the full resulting SQL?
+1
A:
You could use the Log feature on the DataContext and write your own code to evaluate the sql. An example here on logging SQL to the debug window should get you started on pulling out the SQL.
thinkzig
2009-08-13 15:56:16
Hmmm I shall investigate this tomorrow, if it works I'll be a happy SO ticker!
joshcomley
2009-08-13 16:04:17
almost, but no - it's not a query I can run; it's parameterised without the actual values in there like the LINQ to SQL Visualiser provides
joshcomley
2009-08-13 16:03:41
A:
Hi, If your database is SQL server and if you use DBML, you could visualize your Linq queries as native sql queries using Linq to Sql Visualizer. In case you use ADO.NET entity data model against SQL server or any other database server which supports Linq you could use a similar free visualizer available at http://visualstudiogallery.msdn.microsoft.com/en-us/99468ece-689b-481c-868c-19e00e0a4e69
Regards Venkat
Venkat
2010-08-04 17:46:40
A:
If you are using LINQ2SQL you can just call .ToString()
from the composed query.
Matthew Whited
2010-08-04 17:54:53