how do you get LINQ To SQL Output?

2019-05-30 14:59发布

if you have a console application, you can do it very easily. You can assign the console output to the context.log

context.log = console.out;

my application is using asp.net mvc3 and linq to sql. I want to see the raw sql statement after it gets translated, so I can improve the performance. how do i monitor the output?

1条回答
淡お忘
2楼-- · 2019-05-30 15:58

You can do something like this:

var dc = new DataContext(AppSettings.GetConnectionString());
dc.Log = new System.IO.StreamWriter(@"C:\linq.log");

Then just make sure you use that datacontext to get your tables. As soon as that datacontext is used to access the database the SQL will be output to the logfile.

查看更多
登录 后发表回答