Get the App
SLTechnology News&Howtos  ›  Development  › 

How Linq To SQL outputs SQL statements

Shulou Source: shulou.com Published: 2022-06-02 09:15:33 10月05日 Update

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.

Tags: Statement output article different is in more good practical content how to do performance article log time desktop knowledge program reference help influence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Docker Microsoft Shulou Technology