Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Dapper
提交
2ee3202f
D
Dapper
项目概览
int
/
Dapper
11 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dapper
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ee3202f
编写于
6月 28, 2011
作者:
S
Sam Saffron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
the transaction is not really needed there ... it helps with nothing.
上级
e743d345
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
31 deletion
+29
-31
Dapper.Contrib/SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+29
-31
未找到文件。
Dapper.Contrib/SqlMapperExtensions.cs
浏览文件 @
2ee3202f
...
...
@@ -146,44 +146,42 @@ private static string GetTableName(Type type)
/// <returns>Identity of inserted entity</returns>
public
static
long
Insert
<
T
>(
this
IDbConnection
connection
,
T
entityToInsert
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
)
where
T
:
class
{
using
(
var
tx
=
connection
.
BeginTransaction
())
{
var
type
=
typeof
(
T
);
var
type
=
typeof
(
T
);
var
name
=
GetTableName
(
type
);
var
name
=
GetTableName
(
type
);
var
sb
=
new
StringBuilder
(
null
);
sb
.
AppendFormat
(
"insert into {0} ("
,
name
);
var
sb
=
new
StringBuilder
(
null
);
sb
.
AppendFormat
(
"insert into {0} ("
,
name
);
var
allProperties
=
TypePropertiesCache
(
type
);
var
keyProperties
=
KeyPropertiesCache
(
type
);
var
allProperties
=
TypePropertiesCache
(
type
);
var
keyProperties
=
KeyPropertiesCache
(
type
);
for
(
var
i
=
0
;
i
<
allProperties
.
Count
();
i
++)
{
var
property
=
allProperties
.
ElementAt
(
i
);
if
(
keyProperties
.
Contains
(
property
))
continue
;
for
(
var
i
=
0
;
i
<
allProperties
.
Count
();
i
++)
{
var
property
=
allProperties
.
ElementAt
(
i
);
if
(
keyProperties
.
Contains
(
property
))
continue
;
sb
.
Append
(
property
.
Name
);
if
(
i
<
allProperties
.
Count
()
-
1
)
sb
.
Append
(
", "
);
}
sb
.
Append
(
") values ("
);
for
(
var
i
=
0
;
i
<
allProperties
.
Count
();
i
++)
{
var
property
=
allProperties
.
ElementAt
(
i
);
if
(
keyProperties
.
Contains
(
property
))
continue
;
sb
.
Append
(
property
.
Name
);
if
(
i
<
allProperties
.
Count
()
-
1
)
sb
.
Append
(
", "
);
}
sb
.
Append
(
") values ("
);
for
(
var
i
=
0
;
i
<
allProperties
.
Count
();
i
++)
{
var
property
=
allProperties
.
ElementAt
(
i
);
if
(
keyProperties
.
Contains
(
property
))
continue
;
sb
.
AppendFormat
(
"@{0}"
,
property
.
Name
);
if
(
i
<
allProperties
.
Count
()
-
1
)
sb
.
Append
(
", "
);
}
sb
.
Append
(
") "
);
connection
.
Execute
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
var
r
=
connection
.
Query
(
"select @@IDENTITY id"
);
tx
.
Commit
();
return
(
int
)
r
.
First
().
id
;
sb
.
AppendFormat
(
"@{0}"
,
property
.
Name
);
if
(
i
<
allProperties
.
Count
()
-
1
)
sb
.
Append
(
", "
);
}
sb
.
Append
(
") "
);
connection
.
Execute
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
var
r
=
connection
.
Query
(
"select @@IDENTITY id"
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
return
(
int
)
r
.
First
().
id
;
}
/// <summary>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录