Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s0611163
Dapper.LiteSql
提交
7766b293
D
Dapper.LiteSql
项目概览
s0611163
/
Dapper.LiteSql
9 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dapper.LiteSql
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7766b293
编写于
9月 27, 2022
作者:
s0611163
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ISession接口增加 从连接池池获取连接方法 供直接调用Dapper方法使用。
上级
f47e6938
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
158 addition
and
2 deletion
+158
-2
Dapper.LiteSql/Dapper.LiteSql/Session/DBSession.cs
Dapper.LiteSql/Dapper.LiteSql/Session/DBSession.cs
+18
-0
Dapper.LiteSql/Dapper.LiteSql/Session/DBSessionTransaction.cs
...er.LiteSql/Dapper.LiteSql/Session/DBSessionTransaction.cs
+2
-1
Dapper.LiteSql/Dapper.LiteSql/Session/ISession.cs
Dapper.LiteSql/Dapper.LiteSql/Session/ISession.cs
+12
-0
Dapper.LiteSql/Dapper.LiteSql/Session/ISessionTransaction.cs
Dapper.LiteSql/Dapper.LiteSql/Session/ISessionTransaction.cs
+1
-1
Dapper.LiteSql/Dapper.LiteSqlTest/Dapper.LiteSqlTest.csproj
Dapper.LiteSql/Dapper.LiteSqlTest/Dapper.LiteSqlTest.csproj
+5
-0
Dapper.LiteSql/Dapper.LiteSqlTest/DapperTest.cs
Dapper.LiteSql/Dapper.LiteSqlTest/DapperTest.cs
+116
-0
Dapper.LiteSql/Dapper.LiteSqlTest/packages.config
Dapper.LiteSql/Dapper.LiteSqlTest/packages.config
+4
-0
未找到文件。
Dapper.LiteSql/Dapper.LiteSql/Session/DBSession.cs
浏览文件 @
7766b293
...
@@ -210,5 +210,23 @@ namespace Dapper.LiteSql
...
@@ -210,5 +210,23 @@ namespace Dapper.LiteSql
}
}
#
endregion
#
endregion
#
region
从连接池池获取连接
/// <summary>
/// 从连接池池获取连接
/// </summary>
public
DbConnectionExt
GetConnection
(
DbTransactionExt
_tran
=
null
)
{
return
_connFactory
.
GetConnection
(
_tran
);
}
/// <summary>
/// 从连接池池获取连接
/// </summary>
public
Task
<
DbConnectionExt
>
GetConnectionAsync
(
DbTransactionExt
_tran
=
null
)
{
return
_connFactory
.
GetConnectionAsync
(
_tran
);
}
#
endregion
}
}
}
}
Dapper.LiteSql/Dapper.LiteSql/Session/DBSessionTransaction.cs
浏览文件 @
7766b293
...
@@ -12,10 +12,11 @@ namespace Dapper.LiteSql
...
@@ -12,10 +12,11 @@ namespace Dapper.LiteSql
/// <summary>
/// <summary>
/// 开始事务
/// 开始事务
/// </summary>
/// </summary>
public
void
BeginTransaction
()
public
DbTransactionExt
BeginTransaction
()
{
{
_conn
=
_connFactory
.
GetConnection
(
null
);
_conn
=
_connFactory
.
GetConnection
(
null
);
_tran
=
new
DbTransactionExt
(
_conn
.
Conn
.
BeginTransaction
(),
_conn
);
_tran
=
new
DbTransactionExt
(
_conn
.
Conn
.
BeginTransaction
(),
_conn
);
return
_tran
;
}
}
#
endregion
#
endregion
...
...
Dapper.LiteSql/Dapper.LiteSql/Session/ISession.cs
浏览文件 @
7766b293
...
@@ -60,5 +60,17 @@ namespace Dapper.LiteSql
...
@@ -60,5 +60,17 @@ namespace Dapper.LiteSql
SqlValue
ForList
(
IList
list
);
SqlValue
ForList
(
IList
list
);
#
endregion
#
endregion
#
region
从连接池池获取连接
/// <summary>
/// 从连接池池获取连接
/// </summary>
DbConnectionExt
GetConnection
(
DbTransactionExt
_tran
=
null
);
/// <summary>
/// 从连接池池获取连接
/// </summary>
Task
<
DbConnectionExt
>
GetConnectionAsync
(
DbTransactionExt
_tran
=
null
);
#
endregion
}
}
}
}
Dapper.LiteSql/Dapper.LiteSql/Session/ISessionTransaction.cs
浏览文件 @
7766b293
...
@@ -12,7 +12,7 @@ namespace Dapper.LiteSql
...
@@ -12,7 +12,7 @@ namespace Dapper.LiteSql
/// <summary>
/// <summary>
/// 开始事务
/// 开始事务
/// </summary>
/// </summary>
void
BeginTransaction
();
DbTransactionExt
BeginTransaction
();
#
endregion
#
endregion
#
region
提交事务
#
region
提交事务
...
...
Dapper.LiteSql/Dapper.LiteSqlTest/Dapper.LiteSqlTest.csproj
浏览文件 @
7766b293
...
@@ -36,6 +36,9 @@
...
@@ -36,6 +36,9 @@
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Dapper.2.0.123\lib\net461\Dapper.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Configuration"
/>
<Reference
Include=
"System.Configuration"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Data"
/>
...
@@ -57,6 +60,7 @@
...
@@ -57,6 +60,7 @@
<Compile
Include=
"AsyncTest.cs"
/>
<Compile
Include=
"AsyncTest.cs"
/>
<Compile
Include=
"BatchInsertTest.cs"
/>
<Compile
Include=
"BatchInsertTest.cs"
/>
<Compile
Include=
"BatchUpdateTest.cs"
/>
<Compile
Include=
"BatchUpdateTest.cs"
/>
<Compile
Include=
"DapperTest.cs"
/>
<Compile
Include=
"DeleteTest.cs"
/>
<Compile
Include=
"DeleteTest.cs"
/>
<Compile
Include=
"InsertTest.cs"
/>
<Compile
Include=
"InsertTest.cs"
/>
<Compile
Include=
"LambdaTest.cs"
/>
<Compile
Include=
"LambdaTest.cs"
/>
...
@@ -88,6 +92,7 @@
...
@@ -88,6 +92,7 @@
<None
Include=
"App.config"
>
<None
Include=
"App.config"
>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
</None>
<None
Include=
"packages.config"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup
/>
<ItemGroup
/>
<Choose>
<Choose>
...
...
Dapper.LiteSql/Dapper.LiteSqlTest/DapperTest.cs
0 → 100644
浏览文件 @
7766b293
using
DAL
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
DAL
;
using
Models
;
using
Utils
;
using
Dapper
;
using
static
Dapper
.
SqlMapper
;
using
System.Data.Common
;
using
System.Threading
;
namespace
Dapper.LiteSqlTest
{
[
TestClass
]
public
class
DapperTest
{
#
region
构造函数
public
DapperTest
()
{
LiteSqlFactory
.
GetSession
();
}
#
endregion
#
region
测试直接使用
Dapper
[
TestMethod
]
public
void
TestUseDapper
()
{
var
session
=
LiteSqlFactory
.
GetSession
();
using
(
var
conn
=
session
.
GetConnection
())
{
DynamicParameters
dynamicParameters
=
new
DynamicParameters
();
dynamicParameters
.
Add
(
"id"
,
20
);
List
<
SysUser
>
list
=
conn
.
Conn
.
Query
<
SysUser
>(
@"
select id, user_name as UserName, real_name as RealName,
password, remark,
create_userid as CreateUserid, create_time as CreateTime,
update_userid as UpdateUserid, update_time as UpdateTime
from sys_user
where id < @id"
,
dynamicParameters
).
ToList
();
foreach
(
SysUser
item
in
list
)
{
Console
.
WriteLine
(
ModelToStringUtil
.
ToString
(
item
));
}
}
}
#
endregion
#
region
测试混合并发使用
Dapper
和
LiteSql
[
TestMethod
]
public
void
TestUseDapper2
()
{
ThreadPool
.
SetMinThreads
(
50
,
50
);
Console
.
WriteLine
(
"开始"
);
List
<
Task
>
tasks
=
new
List
<
Task
>();
for
(
int
i
=
0
;
i
<
200
;
i
++)
{
var
task
=
Task
.
Run
(()
=>
{
try
{
var
session
=
LiteSqlFactory
.
GetSession
();
var
list
=
session
.
Queryable
<
SysUser
>().
Where
(
t
=>
t
.
Id
<
20
).
ToList
();
Console
.
WriteLine
(
"Dapper.LiteSql查询成功, count="
+
list
.
Count
);
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
.
ToString
());
}
});
tasks
.
Add
(
task
);
var
task2
=
Task
.
Run
(()
=>
{
try
{
var
session
=
LiteSqlFactory
.
GetSession
();
using
(
var
conn
=
session
.
GetConnection
())
{
DynamicParameters
dynamicParameters
=
new
DynamicParameters
();
dynamicParameters
.
Add
(
"id"
,
20
);
List
<
SysUser
>
list
=
conn
.
Conn
.
Query
<
SysUser
>(
@"
select id, user_name as UserName, real_name as RealName,
password, remark,
create_userid as CreateUserid, create_time as CreateTime,
update_userid as UpdateUserid, update_time as UpdateTime
from sys_user
where id < @id"
,
dynamicParameters
).
ToList
();
Console
.
WriteLine
(
"Dapper查询成功, count="
+
list
.
Count
);
}
}
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
ex
.
ToString
());
}
});
tasks
.
Add
(
task2
);
}
Task
.
WaitAll
(
tasks
.
ToArray
());
Console
.
WriteLine
(
"完成"
);
}
#
endregion
}
}
Dapper.LiteSql/Dapper.LiteSqlTest/packages.config
0 → 100644
浏览文件 @
7766b293
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
package
id
=
"Dapper"
version
=
"2.0.123"
targetFramework
=
"net461"
/>
</
packages
>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录