How can I get sql string, generated by Linq2SQL OR

2019-08-01 12:51发布

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?

标签: linq-to-sql
1条回答
【Aperson】
2楼-- · 2019-08-01 13:08

As @usr mentions, you can use ToString() on the query to get the generated SQL. You can also use the Log 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.

查看更多
登录 后发表回答