Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Dapper
提交
4153d2d8
D
Dapper
项目概览
int
/
Dapper
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
4153d2d8
编写于
9月 15, 2014
作者:
M
Marc Gravell
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #162 from jbattermann/master
Added async/await to Dapper.Rainbow - .Net 4.5 Hooray \o/
上级
4bfa979d
90a28dc4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
219 addition
and
10 deletion
+219
-10
Dapper - VS2012.sln
Dapper - VS2012.sln
+13
-0
Dapper.Rainbow NET45/Dapper.Rainbow NET45.csproj
Dapper.Rainbow NET45/Dapper.Rainbow NET45.csproj
+71
-0
Dapper.Rainbow NET45/DatabaseAsync.cs
Dapper.Rainbow NET45/DatabaseAsync.cs
+127
-0
Dapper.Rainbow.nuspec
Dapper.Rainbow.nuspec
+6
-3
Dapper.Rainbow/Dapper.Rainbow.csproj
Dapper.Rainbow/Dapper.Rainbow.csproj
+0
-5
Dapper.Rainbow/Database.cs
Dapper.Rainbow/Database.cs
+2
-2
未找到文件。
Dapper - VS2012.sln
浏览文件 @
4153d2d8
...
...
@@ -31,6 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Dapper.Contrib.nuspec = Dapper.Contrib.nuspec
Dapper.EntityFramework.nuspec = Dapper.EntityFramework.nuspec
Dapper.nuspec = Dapper.nuspec
Dapper.Rainbow.nuspec = Dapper.Rainbow.nuspec
License.txt = License.txt
EndProjectSection
EndProject
...
...
@@ -42,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.EntityFramework NET4
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.Contrib NET45", "Dapper.Contrib NET45\Dapper.Contrib NET45.csproj", "{302EC82F-A81B-48C5-B653-B5C75D2BD103}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.Rainbow NET45", "Dapper.Rainbow NET45\Dapper.Rainbow NET45.csproj", "{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -182,6 +185,16 @@ Global
{302EC82F-A81B-48C5-B653-B5C75D2BD103}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{302EC82F-A81B-48C5-B653-B5C75D2BD103}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{302EC82F-A81B-48C5-B653-B5C75D2BD103}.Release|x86.ActiveCfg = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Debug|x86.ActiveCfg = Debug|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Any CPU.Build.0 = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
Dapper.Rainbow NET45/Dapper.Rainbow NET45.csproj
0 → 100644
浏览文件 @
4153d2d8
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"12.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition=
"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProjectGuid>
{DB42428F-3C2B-4C9E-9B7A-5E43B53D6613}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
Dapper.Rainbow
</RootNamespace>
<AssemblyName>
Dapper.Rainbow
</AssemblyName>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE;ASYNC
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE;ASYNC
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.XML"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\Dapper.Rainbow\Database.cs"
>
<Link>
Database.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\IgnorePropertyAttribute.cs"
>
<Link>
IgnorePropertyAttribute.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\Properties\AssemblyInfo.cs"
>
<Link>
Properties\AssemblyInfo.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\Snapshotter.cs"
>
<Link>
Snapshotter.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Rainbow\SqlCompactDatabase.cs"
>
<Link>
SqlCompactDatabase.cs
</Link>
</Compile>
<Compile
Include=
"DatabaseAsync.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Dapper NET45\Dapper NET45.csproj"
>
<Project>
{0fff5bc7-0a4b-4d87-835e-4fad70937507}
</Project>
<Name>
Dapper NET45
</Name>
</ProjectReference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
Dapper.Rainbow NET45/DatabaseAsync.cs
0 → 100644
浏览文件 @
4153d2d8
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data.Common
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Dapper
{
public
abstract
partial
class
Database
<
TDatabase
>
:
IDisposable
where
TDatabase
:
Database
<
TDatabase
>,
new
()
{
public
partial
class
Table
<
T
,
TId
>
{
/// <summary>
/// Insert a row into the db asynchronously
/// </summary>
/// <param name="data">Either DynamicParameters or an anonymous type or concrete type</param>
/// <returns></returns>
public
virtual
async
Task
<
int
?>
InsertAsync
(
dynamic
data
)
{
var
o
=
(
object
)
data
;
List
<
string
>
paramNames
=
GetParamNames
(
o
);
paramNames
.
Remove
(
"Id"
);
string
cols
=
string
.
Join
(
","
,
paramNames
);
string
cols_params
=
string
.
Join
(
","
,
paramNames
.
Select
(
p
=>
"@"
+
p
));
var
sql
=
"set nocount on insert "
+
TableName
+
" ("
+
cols
+
") values ("
+
cols_params
+
") select cast(scope_identity() as int)"
;
return
(
await
database
.
QueryAsync
<
int
?>(
sql
,
o
)).
Single
();
}
/// <summary>
/// Update a record in the DB asynchronously
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
public
async
Task
<
int
>
UpdateAsync
(
TId
id
,
dynamic
data
)
{
List
<
string
>
paramNames
=
GetParamNames
((
object
)
data
);
var
builder
=
new
StringBuilder
();
builder
.
Append
(
"update "
).
Append
(
TableName
).
Append
(
" set "
);
builder
.
AppendLine
(
string
.
Join
(
","
,
paramNames
.
Where
(
n
=>
n
!=
"Id"
).
Select
(
p
=>
p
+
"= @"
+
p
)));
builder
.
Append
(
"where Id = @Id"
);
DynamicParameters
parameters
=
new
DynamicParameters
(
data
);
parameters
.
Add
(
"Id"
,
id
);
return
await
database
.
ExecuteAsync
(
builder
.
ToString
(),
parameters
);
}
/// <summary>
/// Delete a record for the DB asynchronously
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public
async
Task
<
bool
>
DeleteAsync
(
TId
id
)
{
return
(
await
database
.
ExecuteAsync
(
"delete from "
+
TableName
+
" where Id = @id"
,
new
{
id
}))
>
0
;
}
/// <summary>
/// Grab a record with a particular Id from the DB asynchronously
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public
async
Task
<
T
>
GetAsync
(
TId
id
)
{
return
(
await
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
+
" where Id = @id"
,
new
{
id
})).
FirstOrDefault
();
}
public
virtual
async
Task
<
T
>
FirstAsync
()
{
return
(
await
database
.
QueryAsync
<
T
>(
"select top 1 * from "
+
TableName
)).
FirstOrDefault
();
}
public
async
Task
<
IEnumerable
<
T
>>
AllAsync
()
{
return
await
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
);
}
}
public
async
Task
<
int
>
ExecuteAsync
(
string
sql
,
dynamic
param
=
null
)
{
return
await
connection
.
ExecuteAsync
(
sql
,
param
as
object
,
transaction
,
this
.
commandTimeout
);
}
public
async
Task
<
IEnumerable
<
T
>>
QueryAsync
<
T
>(
string
sql
,
dynamic
param
=
null
)
{
return
await
connection
.
QueryAsync
<
T
>(
sql
,
param
as
object
,
transaction
,
commandTimeout
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TThird
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TThird
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
TReturn
>>
QueryAsync
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TReturn
>(
string
sql
,
Func
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TReturn
>
map
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
string
splitOn
=
"Id"
,
int
?
commandTimeout
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
}
public
async
Task
<
IEnumerable
<
dynamic
>>
QueryAsync
(
string
sql
,
dynamic
param
=
null
)
{
return
await
connection
.
QueryAsync
(
sql
,
param
as
object
,
transaction
);
}
public
async
Task
<
SqlMapper
.
GridReader
>
QueryMultipleAsync
(
string
sql
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
)
{
return
await
SqlMapper
.
QueryMultipleAsync
(
connection
,
sql
,
param
,
transaction
,
commandTimeout
,
commandType
);
}
}
}
Dapper.Rainbow
/Dapper.Rainbow
.nuspec
→
Dapper.Rainbow.nuspec
浏览文件 @
4153d2d8
...
...
@@ -2,7 +2,7 @@
<package
>
<metadata>
<id>
Dapper.Rainbow
</id>
<version>
0.
1.2
</version>
<version>
0.
2.0
</version>
<title>
Dapper.Rainbow
</title>
<authors>
Sam Saffron
</authors>
<owners>
Sam Saffron
</owners>
...
...
@@ -18,6 +18,8 @@
Data explorer uses "Rainbow" exclusively for all database access.
</summary>
<releaseNotes>
* version 0.2:
.Net 4.5 async/await capability added.
* version 0.1:
A demo is available at https://gist.github.com/1599013 .
The implementation was extracted from http://data.stackexchange.com source at: http://code.google.com/p/stack-exchange-data-explorer/ .
...
...
@@ -26,10 +28,11 @@
<copyright>
Copyright Sam Saffron 2012
</copyright>
<tags>
orm dapper micro-orm
</tags>
<dependencies>
<dependency
id=
"Dapper"
version=
"1.
8
"
/>
<dependency
id=
"Dapper"
version=
"1.
34
"
/>
</dependencies>
</metadata>
<files>
<file
src=
"bin\Release\Dapper.Rainbow.dll"
target=
"lib\net40"
/>
<file
src=
"Dapper.Rainbow NET45\bin\Release\Dapper.Rainbow.*"
target=
"lib\net45"
/>
<file
src=
"Dapper.Rainbow\bin\Release\Dapper.Rainbow.*"
target=
"lib\net40"
/>
</files>
</package>
\ No newline at end of file
Dapper.Rainbow/Dapper.Rainbow.csproj
浏览文件 @
4153d2d8
...
...
@@ -46,11 +46,6 @@
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"SqlCompactDatabase.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"Dapper.Rainbow.nuspec"
>
<SubType>
Designer
</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Dapper NET40\Dapper NET40.csproj"
>
<Project>
{daf737e1-05b5-4189-a5aa-dac6233b64d7}
</Project>
...
...
Dapper.Rainbow/Database.cs
浏览文件 @
4153d2d8
...
...
@@ -22,9 +22,9 @@ namespace Dapper
/// A container for a database, assumes all the tables have an Id column named Id
/// </summary>
/// <typeparam name="TDatabase"></typeparam>
public
abstract
class
Database
<
TDatabase
>
:
IDisposable
where
TDatabase
:
Database
<
TDatabase
>,
new
()
public
abstract
partial
class
Database
<
TDatabase
>
:
IDisposable
where
TDatabase
:
Database
<
TDatabase
>,
new
()
{
public
class
Table
<
T
,
TId
>
public
partial
class
Table
<
T
,
TId
>
{
internal
Database
<
TDatabase
>
database
;
internal
string
tableName
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录