gpt4 book ai didi

c# - 为什么 Dapper 示例中的 #(哈希)

转载 作者:太空狗 更新时间:2023-10-29 20:03:16 26 4
gpt4 key购买 nike

我正在阅读 Dapper“手册”中的示例:

connection.Execute(@"
set nocount on
create table #t(i int)
set nocount off
insert #t
select @a a union all select @b
set nocount on
drop table #t", new {a=1, b=2 })
.IsEqualTo(2);

#t 是某种特殊语法吗?或者他们只是为了迷惑我? :)

最佳答案

是的,# 在 TSQL 中意味着一些重要的东西——一个名为 foo 的表对于那个 db/schema 是永久的。名为 #foo 的表是一个临时表 - 它仅存在于该连接中,并在连接关闭或重置时被删除。名为 ##foo 的表是一个 global 临时表,无处不在,但旨在成为临时表。这主要在批量移动数据时使用。

这里使用 #t 是为了让表只存在于那个连接上,所以我们可以简单地重新运行测试。

另外,一个名为@foo 的表要么是一个表变量,要么是一个表值参数,并且只存在于该命令/存储过程。

关于c# - 为什么 Dapper 示例中的 #(哈希),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12860060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com