So, actually this is a main question : How can I get sql string, generated by Linq2SQL ORM? I am familiar with other ORM systems, such as nHibernate and EntityFramework (4+). For instance, for nHibernate exist profiler witch allow to catch any activity, performing by nHibernate engine. In the other hand, EntityFramework has build-in functionality - method
query.ToSqlString()
And what about Linq2SQL?
As @usr mentions, you can use
ToString()
on the query to get the generated SQL. You can also use theLog
property on the linq data context to dump all SQL commands.Another general option is to use the SQL Server Profiler to watch all queries as they come in to the server. That will work for all ORM.