惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 天使爱比目鱼

微软日期格式的改变造成程序崩溃 .NET 中DataGridViewComboBoxCell控件得Bug VB.NET在基类中定义共享事件(类似于C#中的静态事件) 也谈解决Combobox绑定数据后取值出现System.Data.DataRowView的问题 在SQL Server 2014下面使用的SQL2000的Northwind和Pubs示例数据库 去除Linq to Sql 查询结果中的空格 VS2015中DataGridView的DataGridViewComBoboxCell列值无效及数据绑定错误的解决方法 DevExpress学习笔记1-ProductsDemo.Win 在VB中使用Linq To SQLite注意事项 在VB中利用Nuget包使用SQLite数据库和Linq to SQLite 在C#中利用Nuget包使用SQLite数据库和Linq to SQLite VB.NET中使用Linq TO SQL添加数据后获得自增长列ID Linq to SQL 绑定 ComboBox 在VS.NET中根据条件设置不同的MainForm 在T-SQL中使用参数将XML数据添加到SQL数据库的XML列 [转载自键舞者]SELECT IDENT_CURRENT(tableName)获得自增长列ID的实现 测试Windows Live Writer 4步搞定:系统必备的安装位置未设置为组件供应商的网站,无法在磁盘上找到 dotNetFx40LP_Client_x86_x64cs.exe 问题的解决方案 VS2010 SP1 简体中文测试通过,繁体未测试 控件命名规范(转自CSDN)
[转载代码]VB.NET 中查询 Linq to SQL 执行时的SQL语句
天使爱比目鱼 · 2013-07-27 · via 博客园 - 天使爱比目鱼

在搜索使用LINQ TO SQL 添加数据后获得自增长ID的方法时,发现C#可以使用DebuggerWritter把使用Linq to SQL执行的SQL语句显示到即时窗口,于是在网上搜索到在VB.NET下实现的方法,共享给大家:

1、首先在项目内添加新类,命名为:DebuggerWritter.vb

 

2、输入代码后保存:

Imports System.Diagnostics
Imports System.Globalization
Imports System.IO
Imports System.Text


''' <summary>
''' Implements a <see cref="TextWriter"/> for writing information to the debugger log.
''' </summary>
''' <seealso cref="Debugger.Log"/>
Public Class DebuggerWriter
    Inherits TextWriter
    Private _isOpen As Boolean
    Private Shared _encoding As UnicodeEncoding
    Private ReadOnly _level As Integer
    Private ReadOnly _category As String

    ''' <summary>
    ''' Initializes a new instance of the <see cref="DebuggerWriter"/> class.
    ''' </summary>
    Public Sub New()
        Me.New(0, Debugger.DefaultCategory)
    End Sub

    ''' <summary>
    ''' Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level and category.
    ''' </summary>
    ''' <param name="level">A description of the importance of the messages.</param>
    ''' <param name="category">The category of the messages.</param>
    Public Sub New(ByVal level As Integer, ByVal category As String)
        Me.New(level, category, CultureInfo.CurrentCulture)
    End Sub

    ''' <summary>
    ''' Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level, category and format provider.
    ''' </summary>
    ''' <param name="level">A description of the importance of the messages.</param>
    ''' <param name="category">The category of the messages.</param>
    ''' <param name="formatProvider">An <see cref="IFormatProvider"/> object that controls formatting.</param>
    Public Sub New(ByVal level As Integer, ByVal category As String, ByVal formatProvider As IFormatProvider)
        MyBase.New(formatProvider)
        Me._level = level
        Me._category = category
        Me._isOpen = True
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        _isOpen = False
        MyBase.Dispose(disposing)
    End Sub

    Public Overloads Overrides Sub Write(ByVal value As Char)
        If Not _isOpen Then
            Throw New ObjectDisposedException(Nothing)
        End If
        Debugger.Log(level, category, value.ToString())
    End Sub

    Public Overloads Overrides Sub Write(ByVal value As String)
        If Not _isOpen Then
            Throw New ObjectDisposedException(Nothing)
        End If
        If value <> Nothing Then
            Debugger.Log(level, category, value)
        End If
    End Sub

    Public Overloads Overrides Sub Write(ByVal buffer As Char(), ByVal index As Integer, ByVal count As Integer)
        If Not _isOpen Then
            Throw New ObjectDisposedException(Nothing)
        End If
        If buffer = Nothing OrElse index < 0 OrElse count < 0 OrElse buffer.Length - index < count Then
            ' delegate throw exception to base class
            MyBase.Write(buffer, index, count)
        End If
        Debugger.Log(level, category, New String(buffer, index, count))
    End Sub

    Public Overloads Overrides ReadOnly Property Encoding() As Encoding
        Get
            If _encoding Is Nothing Then
                _encoding = New UnicodeEncoding(False, False)
            End If
            Return _encoding
        End Get
    End Property

    Public ReadOnly Property Level() As Integer
        Get
            Return Level
        End Get
    End Property

    Public ReadOnly Property Category() As String
        Get
            Return _category
        End Get
    End Property
End Class

3、在项目中添加对System.Transactions的引用:

4、在Linq TO SQL执行处添加代码:

Dim tran As New Transactions.TransactionScope
Using tran
     db.Log = New DebuggerWriter
     db.SubmitChanges()
     tran.Dispose()
End Using

5、在VS.NET中打开“即时窗口”

6、运行程序,即可在“即时窗口”中看到转换后的SQL代码:

最后注意:这种方法运行程序后执行的操作只反映在“即时窗口”中,并不会真正的更改数据库内容,所以在调试完成后请将调试代码删除。