Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
4be8df79
Commit
4be8df79
authored
May 06, 2017
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lots of documentation fixes/additions.
parent
7820ee2e
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
582 additions
and
57 deletions
+582
-57
SqlMapperExtensions.Async.cs
Dapper.Contrib/SqlMapperExtensions.Async.cs
+85
-1
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+232
-7
Database.Async.cs
Dapper.Rainbow/Database.Async.cs
+66
-12
Database.cs
Dapper.Rainbow/Database.cs
+125
-18
IgnorePropertyAttribute.cs
Dapper.Rainbow/IgnorePropertyAttribute.cs
+10
-0
Snapshotter.cs
Dapper.Rainbow/Snapshotter.cs
+39
-12
SqlCompactDatabase.cs
Dapper.Rainbow/SqlCompactDatabase.cs
+20
-2
PetaPoco.cs
Dapper.Tests.Performance/PetaPoco/PetaPoco.cs
+1
-1
DynamicParameters.cs
Dapper/DynamicParameters.cs
+2
-2
SqlMapper.DapperRow.cs
Dapper/SqlMapper.DapperRow.cs
+2
-2
No files found.
Dapper.Contrib/SqlMapperExtensions.Async.cs
View file @
4be8df79
...
@@ -306,11 +306,35 @@ public static partial class SqlMapperExtensions
...
@@ -306,11 +306,35 @@ public static partial class SqlMapperExtensions
public
partial
interface
ISqlAdapter
public
partial
interface
ISqlAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
String
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
);
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
String
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
);
}
}
public
partial
class
SqlServerAdapter
public
partial
class
SqlServerAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
String
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
String
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
{
var
cmd
=
$"INSERT INTO
{
tableName
}
(
{
columnList
}
) values (
{
parameterList
}
); SELECT SCOPE_IDENTITY() id"
;
var
cmd
=
$"INSERT INTO
{
tableName
}
(
{
columnList
}
) values (
{
parameterList
}
); SELECT SCOPE_IDENTITY() id"
;
...
@@ -332,6 +356,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
...
@@ -332,6 +356,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
public
partial
class
SqlCeServerAdapter
public
partial
class
SqlCeServerAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
{
var
cmd
=
$"INSERT INTO
{
tableName
}
(
{
columnList
}
) VALUES (
{
parameterList
}
)"
;
var
cmd
=
$"INSERT INTO
{
tableName
}
(
{
columnList
}
) VALUES (
{
parameterList
}
)"
;
...
@@ -353,6 +389,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
...
@@ -353,6 +389,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
public
partial
class
MySqlAdapter
public
partial
class
MySqlAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
{
...
@@ -373,7 +421,19 @@ public partial class MySqlAdapter
...
@@ -373,7 +421,19 @@ public partial class MySqlAdapter
}
}
public
partial
class
PostgresAdapter
public
partial
class
PostgresAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
{
var
sb
=
new
StringBuilder
();
var
sb
=
new
StringBuilder
();
...
@@ -414,6 +474,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
...
@@ -414,6 +474,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
public
partial
class
SQLiteAdapter
public
partial
class
SQLiteAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
{
var
cmd
=
$"INSERT INTO
{
tableName
}
(
{
columnList
}
) VALUES (
{
parameterList
}
); SELECT last_insert_rowid() id"
;
var
cmd
=
$"INSERT INTO
{
tableName
}
(
{
columnList
}
) VALUES (
{
parameterList
}
); SELECT last_insert_rowid() id"
;
...
@@ -432,6 +504,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
...
@@ -432,6 +504,18 @@ public async Task<int> InsertAsync(IDbConnection connection, IDbTransaction tran
public
partial
class
FbAdapter
public
partial
class
FbAdapter
{
{
/// <summary>
/// Inserts <paramref name="entityToInsert"/> into the database, returning the Id of the row created.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <param name="transaction">The transaction to use.</param>
/// <param name="commandTimeout">The command timeout to use.</param>
/// <param name="tableName">The table to insert into.</param>
/// <param name="columnList">The columns to set with this insert.</param>
/// <param name="parameterList">The parameters to set for this insert.</param>
/// <param name="keyProperties">The key columns in this table.</param>
/// <param name="entityToInsert">The entity to insert.</param>
/// <returns>The Id of the row created.</returns>
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
public
async
Task
<
int
>
InsertAsync
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
string
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
{
var
cmd
=
$"insert into
{
tableName
}
(
{
columnList
}
) values (
{
parameterList
}
)"
;
var
cmd
=
$"insert into
{
tableName
}
(
{
columnList
}
) values (
{
parameterList
}
)"
;
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
4be8df79
This diff is collapsed.
Click to expand it.
Dapper.Rainbow/Database.Async.cs
View file @
4be8df79
...
@@ -45,7 +45,7 @@ public Task<int> UpdateAsync(TId id, dynamic data)
...
@@ -45,7 +45,7 @@ public Task<int> UpdateAsync(TId id, dynamic data)
builder
.
AppendLine
(
string
.
Join
(
","
,
paramNames
.
Where
(
n
=>
n
!=
"Id"
).
Select
(
p
=>
p
+
"= @"
+
p
)));
builder
.
AppendLine
(
string
.
Join
(
","
,
paramNames
.
Where
(
n
=>
n
!=
"Id"
).
Select
(
p
=>
p
+
"= @"
+
p
)));
builder
.
Append
(
"where Id = @Id"
);
builder
.
Append
(
"where Id = @Id"
);
DynamicParameters
parameters
=
new
DynamicParameters
(
data
);
var
parameters
=
new
DynamicParameters
(
data
);
parameters
.
Add
(
"Id"
,
id
);
parameters
.
Add
(
"Id"
,
id
);
return
database
.
ExecuteAsync
(
builder
.
ToString
(),
parameters
);
return
database
.
ExecuteAsync
(
builder
.
ToString
(),
parameters
);
...
@@ -62,61 +62,115 @@ public async Task<bool> DeleteAsync(TId id)
...
@@ -62,61 +62,115 @@ public async Task<bool> DeleteAsync(TId id)
}
}
/// <summary>
/// <summary>
///
Grab a record with a particular Id from the DB asynchronously
///
Asynchronously gets a record with a particular Id from the DB
/// </summary>
/// </summary>
/// <param name="id"></param>
/// <param name="id">
The primary key of the table to fetch.
</param>
/// <returns></returns>
/// <returns>
The record with the specified Id.
</returns>
public
async
Task
<
T
>
GetAsync
(
TId
id
)
public
Task
<
T
>
GetAsync
(
TId
id
)
{
{
return
(
await
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
+
" where Id = @id"
,
new
{
id
}).
ConfigureAwait
(
false
)).
FirstOrDefault
(
);
return
database
.
QueryFirstOrDefaultAsync
<
T
>(
"select * from "
+
TableName
+
" where Id = @id"
,
new
{
id
}
);
}
}
public
virtual
async
Task
<
T
>
FirstAsync
()
/// <summary>
/// Asynchronously gets the first row from this table (order determined by the database provider).
/// </summary>
/// <returns>Data from the first table row.</returns>
public
virtual
Task
<
T
>
FirstAsync
()
{
{
return
(
await
database
.
QueryAsync
<
T
>(
"select top 1 * from "
+
TableName
).
ConfigureAwait
(
false
)).
FirstOrDefault
(
);
return
database
.
QueryFirstOrDefaultAsync
<
T
>(
"select top 1 * from "
+
TableName
);
}
}
/// <summary>
/// Asynchronously gets the all rows from this table.
/// </summary>
/// <returns>Data from all table rows.</returns>
public
Task
<
IEnumerable
<
T
>>
AllAsync
()
public
Task
<
IEnumerable
<
T
>>
AllAsync
()
{
{
return
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
);
return
database
.
QueryAsync
<
T
>(
"select * from "
+
TableName
);
}
}
}
}
/// <summary>
/// Asynchronously executes SQL against the current database.
/// </summary>
/// <param name="sql">The SQL to execute.</param>
/// <param name="param">The parameters to use.</param>
/// <returns>The number of rows affected.</returns>
public
Task
<
int
>
ExecuteAsync
(
string
sql
,
dynamic
param
=
null
)
public
Task
<
int
>
ExecuteAsync
(
string
sql
,
dynamic
param
=
null
)
{
{
return
_connection
.
ExecuteAsync
(
sql
,
param
as
object
,
_transaction
,
this
.
_commandTimeout
);
return
_connection
.
ExecuteAsync
(
sql
,
param
as
object
,
_transaction
,
this
.
_commandTimeout
);
}
}
/// <summary>
/// Asynchronously queries the current database.
/// </summary>
/// <typeparam name="T">The type to return.</typeparam>
/// <param name="sql">The SQL to execute.</param>
/// <param name="param">The parameters to use.</param>
/// <returns>An enumerable of <typeparamref name="T"/> for the rows fetched.</returns>
public
Task
<
IEnumerable
<
T
>>
QueryAsync
<
T
>(
string
sql
,
dynamic
param
=
null
)
public
Task
<
IEnumerable
<
T
>>
QueryAsync
<
T
>(
string
sql
,
dynamic
param
=
null
)
{
{
return
_connection
.
QueryAsync
<
T
>(
sql
,
param
as
object
,
_transaction
,
_commandTimeout
);
return
_connection
.
QueryAsync
<
T
>(
sql
,
param
as
object
,
_transaction
,
_commandTimeout
);
}
}
/// <summary>
/// Asynchronously queries the current database for a single record.
/// </summary>
/// <typeparam name="T">The type to return.</typeparam>
/// <param name="sql">The SQL to execute.</param>
/// <param name="param">The parameters to use.</param>
/// <returns>An enumerable of <typeparamref name="T"/> for the rows fetched.</returns>
public
Task
<
T
>
QueryFirstOrDefaultAsync
<
T
>(
string
sql
,
dynamic
param
=
null
)
{
return
_connection
.
QueryFirstOrDefaultAsync
<
T
>(
sql
,
param
as
object
,
_transaction
,
_commandTimeout
);
}
/// <summary>
/// Perform an asynchronous multi mapping query with 2 input parameters
/// </summary>
public
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
)
public
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
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
return
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
,
commandTimeout
);
}
}
/// <summary>
/// Perform an asynchronous multi mapping query with 3 input parameters
/// </summary>
public
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
)
public
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
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
return
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
,
commandTimeout
);
}
}
/// <summary>
/// Perform an asynchronous multi mapping query with 4 input parameters
/// </summary>
public
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
)
public
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
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
return
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
,
commandTimeout
);
}
}
/// <summary>
/// Perform an asynchronous multi mapping query with 5 input parameters
/// </summary>
public
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
)
public
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
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
);
return
_connection
.
QueryAsync
(
sql
,
map
,
param
as
object
,
transaction
,
buffered
,
splitOn
,
commandTimeout
);
}
}
/// <summary>
/// Execute a query asynchronously using .NET 4.5 Task.
/// </summary>
/// <param name="sql">The SQL to execute.</param>
/// <param name="param">The parameters to use.</param>
/// <remarks>Note: each row can be accessed via "dynamic", or by casting to an IDictionary<string,object></remarks>
public
Task
<
IEnumerable
<
dynamic
>>
QueryAsync
(
string
sql
,
dynamic
param
=
null
)
public
Task
<
IEnumerable
<
dynamic
>>
QueryAsync
(
string
sql
,
dynamic
param
=
null
)
{
{
return
_connection
.
QueryAsync
(
sql
,
param
as
object
,
_transaction
);
return
_connection
.
QueryAsync
(
sql
,
param
as
object
,
_transaction
);
}
}
/// <summary>
/// Execute a command that returns multiple result sets, and access each in turn
/// </summary>
public
Task
<
SqlMapper
.
GridReader
>
QueryMultipleAsync
(
string
sql
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
)
public
Task
<
SqlMapper
.
GridReader
>
QueryMultipleAsync
(
string
sql
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
)
{
{
return
SqlMapper
.
QueryMultipleAsync
(
_connection
,
sql
,
param
,
transaction
,
commandTimeout
,
commandType
);
return
SqlMapper
.
QueryMultipleAsync
(
_connection
,
sql
,
param
,
transaction
,
commandTimeout
,
commandType
);
...
...
Dapper.Rainbow/Database.cs
View file @
4be8df79
This diff is collapsed.
Click to expand it.
Dapper.Rainbow/IgnorePropertyAttribute.cs
View file @
4be8df79
...
@@ -2,14 +2,24 @@
...
@@ -2,14 +2,24 @@
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// Specifies whether a property should be ignored for database operations.
/// </summary>
[
AttributeUsage
(
AttributeTargets
.
Property
,
AllowMultiple
=
true
)]
[
AttributeUsage
(
AttributeTargets
.
Property
,
AllowMultiple
=
true
)]
public
class
IgnorePropertyAttribute
:
Attribute
public
class
IgnorePropertyAttribute
:
Attribute
{
{
/// <summary>
/// Specifies whether a property should be ignored for database operations.
/// </summary>
/// <param name="ignore">Whether to ignore this property.</param>
public
IgnorePropertyAttribute
(
bool
ignore
)
public
IgnorePropertyAttribute
(
bool
ignore
)
{
{
Value
=
ignore
;
Value
=
ignore
;
}
}
/// <summary>
/// Whether to ignore this property.
/// </summary>
public
bool
Value
{
get
;
set
;
}
public
bool
Value
{
get
;
set
;
}
}
}
}
}
Dapper.Rainbow/Snapshotter.cs
View file @
4be8df79
...
@@ -6,32 +6,62 @@
...
@@ -6,32 +6,62 @@
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// Snapshots an object for comparison later.
/// </summary>
public
static
class
Snapshotter
public
static
class
Snapshotter
{
{
/// <summary>
/// Starts the snapshot of an objec by making a copy of the current state.
/// </summary>
/// <typeparam name="T">The type of object to snapshot.</typeparam>
/// <param name="obj">The object to snapshot.</param>
/// <returns>The snapshot of the object.</returns>
public
static
Snapshot
<
T
>
Start
<
T
>(
T
obj
)
public
static
Snapshot
<
T
>
Start
<
T
>(
T
obj
)
{
{
return
new
Snapshot
<
T
>(
obj
);
return
new
Snapshot
<
T
>(
obj
);
}
}
/// <summary>
/// A snapshot of an object's state.
/// </summary>
/// <typeparam name="T"></typeparam>
public
class
Snapshot
<
T
>
public
class
Snapshot
<
T
>
{
{
static
Func
<
T
,
T
>
cloner
;
private
static
Func
<
T
,
T
>
cloner
;
static
Func
<
T
,
T
,
List
<
Change
>>
differ
;
private
static
Func
<
T
,
T
,
List
<
Change
>>
differ
;
T
memberWiseClone
;
private
readonly
T
memberWiseClone
;
T
trackedObject
;
private
readonly
T
trackedObject
;
/// <summary>
/// Creates a snapshot from an object.
/// </summary>
/// <param name="original">The original object to snapshot.</param>
public
Snapshot
(
T
original
)
public
Snapshot
(
T
original
)
{
{
memberWiseClone
=
Clone
(
original
);
memberWiseClone
=
Clone
(
original
);
trackedObject
=
original
;
trackedObject
=
original
;
}
}
/// <summary>
/// A holder for listing new values of changes fields and properties.
/// </summary>
public
class
Change
public
class
Change
{
{
/// <summary>
/// The name of the field or property that changed.
/// </summary>
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
/// <summary>
/// The new value of the field or property.
/// </summary>
public
object
NewValue
{
get
;
set
;
}
public
object
NewValue
{
get
;
set
;
}
}
}
/// <summary>
/// Does a diff between the original object and the current state.
/// </summary>
/// <returns>The list of the fields changes in the object.</returns>
public
DynamicParameters
Diff
()
public
DynamicParameters
Diff
()
{
{
return
Diff
(
memberWiseClone
,
trackedObject
);
return
Diff
(
memberWiseClone
,
trackedObject
);
...
@@ -65,16 +95,13 @@ static List<PropertyInfo> RelevantProperties()
...
@@ -65,16 +95,13 @@ static List<PropertyInfo> RelevantProperties()
(
p
.
PropertyType
.
IsGenericType
()
&&
p
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>)))
(
p
.
PropertyType
.
IsGenericType
()
&&
p
.
PropertyType
.
GetGenericTypeDefinition
()
==
typeof
(
Nullable
<>)))
).
ToList
();
).
ToList
();
}
}
// This is used by IL, ReSharper is wrong.
// ReSharper disable UnusedMember.Local
private
static
bool
AreEqual
<
U
>(
U
first
,
U
second
)
private
static
bool
AreEqual
<
U
>(
U
first
,
U
second
)
{
{
if
(
first
==
null
&&
second
==
null
)
return
true
;
if
(
EqualityComparer
<
U
>.
Default
.
Equals
(
first
,
default
(
U
))
&&
EqualityComparer
<
U
>.
Default
.
Equals
(
second
,
default
(
U
))
)
return
true
;
if
(
first
==
null
)
return
false
;
if
(
EqualityComparer
<
U
>.
Default
.
Equals
(
first
,
default
(
U
))
)
return
false
;
return
first
.
Equals
(
second
);
return
first
.
Equals
(
second
);
}
}
// ReSharper restore UnusedMember.Local
private
static
Func
<
T
,
T
,
List
<
Change
>>
GenerateDiffer
()
private
static
Func
<
T
,
T
,
List
<
Change
>>
GenerateDiffer
()
{
{
...
@@ -114,7 +141,7 @@ private static bool AreEqual<U>(U first, U second)
...
@@ -114,7 +141,7 @@ private static bool AreEqual<U>(U first, U second)
il
.
Emit
(
OpCodes
.
Stloc_2
);
il
.
Emit
(
OpCodes
.
Stloc_2
);
// [original prop val, current prop val]
// [original prop val, current prop val]
il
.
EmitCall
(
OpCodes
.
Call
,
typeof
(
Snapshot
<
T
>).
GetMethod
(
"AreEqual"
,
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
).
MakeGenericMethod
(
new
Type
[]
{
prop
.
PropertyType
}),
null
);
il
.
EmitCall
(
OpCodes
.
Call
,
typeof
(
Snapshot
<
T
>).
GetMethod
(
nameof
(
AreEqual
)
,
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
).
MakeGenericMethod
(
new
Type
[]
{
prop
.
PropertyType
}),
null
);
// [result]
// [result]
Label
skip
=
il
.
DefineLabel
();
Label
skip
=
il
.
DefineLabel
();
...
...
Dapper.Rainbow/SqlCompactDatabase.cs
View file @
4be8df79
...
@@ -5,10 +5,23 @@
...
@@ -5,10 +5,23 @@
namespace
Dapper
namespace
Dapper
{
{
/// <summary>
/// A SQL Compact specific <see cref="Database{TDatabase}"/> implementation.
/// </summary>
/// <typeparam name="TDatabase">The type of database.</typeparam>
public
abstract
class
SqlCompactDatabase
<
TDatabase
>
:
Database
<
TDatabase
>
where
TDatabase
:
Database
<
TDatabase
>,
new
()
public
abstract
class
SqlCompactDatabase
<
TDatabase
>
:
Database
<
TDatabase
>
where
TDatabase
:
Database
<
TDatabase
>,
new
()
{
{
/// <summary>
/// A SQL Compact specific table, which handles the syntax correctly across operations.
/// </summary>
/// <typeparam name="T">The type in the table.</typeparam>
public
class
SqlCompactTable
<
T
>
:
Table
<
T
>
public
class
SqlCompactTable
<
T
>
:
Table
<
T
>
{
{
/// <summary>
/// Creates a table for a SQL Compact database.
/// </summary>
/// <param name="database"></param>
/// <param name="likelyTableName"></param>
public
SqlCompactTable
(
Database
<
TDatabase
>
database
,
string
likelyTableName
)
public
SqlCompactTable
(
Database
<
TDatabase
>
database
,
string
likelyTableName
)
:
base
(
database
,
likelyTableName
)
:
base
(
database
,
likelyTableName
)
{
{
...
@@ -38,12 +51,17 @@ public SqlCompactTable(Database<TDatabase> database, string likelyTableName)
...
@@ -38,12 +51,17 @@ public SqlCompactTable(Database<TDatabase> database, string likelyTableName)
}
}
}
}
/// <summary>
/// Initializes the databases.
/// </summary>
/// <param name="connection">The connection to use.</param>
/// <returns>The newly created database.</returns>
public
static
TDatabase
Init
(
DbConnection
connection
)
public
static
TDatabase
Init
(
DbConnection
connection
)
{
{
TDatabase
db
=
new
TDatabase
();
var
db
=
new
TDatabase
();
db
.
InitDatabase
(
connection
,
0
);
db
.
InitDatabase
(
connection
,
0
);
return
db
;
return
db
;
}
}
internal
override
Action
<
TDatabase
>
CreateTableConstructorForTable
()
internal
override
Action
<
TDatabase
>
CreateTableConstructorForTable
()
{
{
...
...
Dapper.Tests.Performance/PetaPoco/PetaPoco.cs
View file @
4be8df79
...
@@ -1112,7 +1112,7 @@ public PocoData(Type t)
...
@@ -1112,7 +1112,7 @@ public PocoData(Type t)
{
{
var
colattr
=
(
Column
)
ColAttrs
[
0
];
var
colattr
=
(
Column
)
ColAttrs
[
0
];
pc
.
ColumnName
=
colattr
.
Name
;
pc
.
ColumnName
=
colattr
.
Name
;
if
(
(
colattr
as
ResultColumn
)
!=
null
)
if
(
colattr
is
ResultColumn
)
pc
.
ResultColumn
=
true
;
pc
.
ResultColumn
=
true
;
}
}
if
(
pc
.
ColumnName
==
null
)
if
(
pc
.
ColumnName
==
null
)
...
...
Dapper/DynamicParameters.cs
View file @
4be8df79
...
@@ -24,12 +24,12 @@ public partial class DynamicParameters : SqlMapper.IDynamicParameters, SqlMapper
...
@@ -24,12 +24,12 @@ public partial class DynamicParameters : SqlMapper.IDynamicParameters, SqlMapper
Dictionary
<
string
,
ParamInfo
>
parameters
=
new
Dictionary
<
string
,
ParamInfo
>();
Dictionary
<
string
,
ParamInfo
>
parameters
=
new
Dictionary
<
string
,
ParamInfo
>();
List
<
object
>
templates
;
List
<
object
>
templates
;
object
SqlMapper
.
IParameterLookup
.
this
[
string
member
]
object
SqlMapper
.
IParameterLookup
.
this
[
string
name
]
{
{
get
get
{
{
ParamInfo
param
;
ParamInfo
param
;
return
parameters
.
TryGetValue
(
member
,
out
param
)
?
param
.
Value
:
null
;
return
parameters
.
TryGetValue
(
name
,
out
param
)
?
param
.
Value
:
null
;
}
}
}
}
...
...
Dapper/SqlMapper.DapperRow.cs
View file @
4be8df79
...
@@ -39,9 +39,9 @@ private sealed class DeadValue
...
@@ -39,9 +39,9 @@ private sealed class DeadValue
}
}
}
}
public
bool
TryGetValue
(
string
name
,
out
object
value
)
public
bool
TryGetValue
(
string
key
,
out
object
value
)
{
{
var
index
=
table
.
IndexOfName
(
name
);
var
index
=
table
.
IndexOfName
(
key
);
if
(
index
<
0
)
if
(
index
<
0
)
{
// doesn't exist
{
// doesn't exist
value
=
null
;
value
=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment