添加SQL注释到Linq生成的查询,以便它在SQL分析器中可见 [英] Adding SQL comment to Linq generated query so that it is visible in SQL profiler
问题描述
我们想使用LINQ to SQL中的一个项目。这是我们第一次使用Linq。通常情况下,我们使用时只需调用存储过程。
We want to use Linq to SQL for a project. That's the first time we use Linq. Typically we use just stored procedure calls.
到目前为止,一切是伟大的工作,但DBA的都在问我们是否可以标记的LINQ生成的SQL查询的方式,是在探查可见。
So far everything is working great, but the DBA's are asking us whether we can mark the Linq generated SQL queries in a way that is visible in Profiler.
我GOOGLE了搜查和#1,我发现不同的方式来记录生成的SQL。但是,这不正是我想要的。我认为理想的情况是,如果我能坚持一个SQL注释到生成的SQL。将在探查可见?
I googled and searched Stackoverflow and I found various ways to log the generated SQL. But that's not exactly what I want. I think ideal would be if I could stick a SQL comment into the generated SQL. Would that be visible in Profiler?
感谢您的任何想法!
推荐答案
您可以使用包含特定的应用程序名来标识的LINQ to SQL查询的唯一连接字符串
You could use a unique connection string that includes a specific "Application Name" to identify LINQ to SQL queries.
下面是如何设置应用程序的名称在代码的例子:
Here is an example of how you can set the Application Name in code:
string connectionString = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
builder.ApplicationName = "linqtosql";
using (var context = new DataContext(builder.ConnectionString)) {
var list = context.Customers.ToList();
}
这篇关于添加SQL注释到Linq生成的查询,以便它在SQL分析器中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!