开发者

how do you get LINQ To SQL Output?

开发者 https://www.devze.com 2023-03-25 04:08 出处:网络
if you have a console application, you can do it very easily.You can assign the console output to the context.log

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开发者_C百科 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号