如何获得LINQ To SQL输出? [英] how do you get LINQ To SQL Output?

查看:103
本文介绍了如何获得LINQ To SQL输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有控制台应用程序,则可以轻松完成.您可以将控制台输出分配给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;

context.log = console.out;

我的应用程序使用asp.net mvc3和linq到sql.转换后,我想查看原始的sql语句,因此可以提高性能.如何监视输出?

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?

推荐答案

您可以执行以下操作:

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

然后确保您使用该数据上下文获取表.一旦使用该数据上下文访问数据库,SQL就会输出到日志文件.

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.

这篇关于如何获得LINQ To SQL输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆