Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Linq To SQL outputs SQL statements

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how Linq To SQL outputs SQL statements. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

Recently, when using Linq To SQL, in order to understand the different performance impacts of different Linq statements, you need to obtain Linq To SQL output SQL statements.

If it's in a desktop application, you just need

_context.Log = Console.Out;

Linq To SQL output SQL statements. But what about ASP.NET? Then I remembered StringWriter. Instead of Console.Out, it can help us receive the output logs and save them in a StringBuilder.

So construct an auxiliary 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); } } } About "Linq To SQL how to output SQL statements" This article is shared here, I hope the above content can have some help for everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report