Adding a SQL comment to a Linq-called query so that it can be seen in the SQL Profiler

We want to use Linq for SQL for the project. This is the first time we use Linq. Usually we use only stored procedure calls.

So far, everything is working fine, but the database administrator asks us if we can mark the created Linq SQL queries in the way that is displayed in Profiler.

I googled and searched for Stackoverflow, and I found various ways to register the generated SQL. But this is not exactly what I want. I think it would be ideal if I could insert a SQL comment into the generated SQL. Will this be visible in Profiler?

Thanks for any ideas!

+4
source share
1 answer

You can use a unique connection string that includes a specific "Application Name" to identify LINQ to SQL queries.

alt text

alt text

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(); } 
+9
source

Source: https://habr.com/ru/post/1334218/


All Articles