Measure the test taker's knowledge about the performance of the LINQ statement in ASP. NET programming.

Source: Internet
Author: User

In a desktop program

_ Context. Log = Console. Out;

You can output SQL statements on the console. But what should I do in ASP. NET?

Now I think of StringWriter. Instead of Console. Out, you can use it to receive output logs and store them in a StringBuilder.

Construct a helper class:

Using System; using System. collections. generic; using System. linq; using System. web; using System. IO; using System. text; namespace Clowwindy. models {public static class LogHelper {public static StringBuilder Log = new StringBuilder (); public static TextWriter In = new StringWriter (Log); public static string GetAllLog () {In. flush (); return Log. toString () ;}public static void Clean () {Log = new StringBuilder (); In = new StringWriter (Log );}}}

Add a page log. aspx to display the log:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Log. aspx. cs" Inherits = "Clowwindy. Log" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using Clowwindy. models; namespace Clowwindy {public partial class Log: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {if (Request. userHostAddress! = "127.0.0.1") {Response. end (); return;} Literal1.Text = LogHelper. getAllLog (). replace ("\ n", "\ n <br/>");} protected void btn_Clean_Click (object sender, EventArgs e) {LogHelper. clean (); Literal1.Text = null ;}}}

Add _ context. Log = LogHelper. In to all new DataContext:

Public Repository () {_ context = new TDataContext (); _ context. Log = LogHelper. In ;}

Open log. aspx and you will see the previously executed SQL statement.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.