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
8c7a14cd
Commit
8c7a14cd
authored
Nov 25, 2015
by
Marc Gravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:StackExchange/dapper-dot-net
parents
0f218852
336cacbe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
18 deletions
+17
-18
SqlMapperExtensions.Async.cs
Dapper.Contrib/SqlMapperExtensions.Async.cs
+10
-9
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+7
-7
TestSuite.Async.cs
Dapper.Tests.Contrib/TestSuite.Async.cs
+0
-2
No files found.
Dapper.Contrib/SqlMapperExtensions.Async.cs
View file @
8c7a14cd
...
...
@@ -127,10 +127,11 @@ public static partial class SqlMapperExtensions
public
static
async
Task
<
int
>
InsertAsync
<
T
>(
this
IDbConnection
connection
,
T
entityToInsert
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
ISqlAdapter
sqlAdapter
=
null
)
where
T
:
class
{
var
isList
=
false
;
var
type
=
typeof
(
T
);
if
(
sqlAdapter
==
null
)
sqlAdapter
=
GetFormatter
(
connection
);
var
isList
=
false
;
if
(
type
.
IsArray
||
type
.
IsGenericType
())
{
isList
=
true
;
...
...
@@ -147,7 +148,7 @@ public static partial class SqlMapperExtensions
for
(
var
i
=
0
;
i
<
allPropertiesExceptKeyAndComputed
.
Count
;
i
++)
{
var
property
=
allPropertiesExceptKeyAndComputed
.
ElementAt
(
i
);
s
bColumnList
.
AppendFormat
(
"[{0}]"
,
property
.
Name
);
s
qlAdapter
.
AppendColumnName
(
sbColumnList
,
property
.
Name
);
if
(
i
<
allPropertiesExceptKeyAndComputed
.
Count
-
1
)
sbColumnList
.
Append
(
", "
);
}
...
...
@@ -163,8 +164,6 @@ public static partial class SqlMapperExtensions
if
(!
isList
)
//single entity
{
if
(
sqlAdapter
==
null
)
sqlAdapter
=
GetFormatter
(
connection
);
return
await
sqlAdapter
.
InsertAsync
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
sbParameterList
.
ToString
(),
keyProperties
,
entityToInsert
);
}
...
...
@@ -211,10 +210,12 @@ public static partial class SqlMapperExtensions
var
computedProperties
=
ComputedPropertiesCache
(
type
);
var
nonIdProps
=
allProperties
.
Except
(
keyProperties
.
Union
(
computedProperties
)).
ToList
();
var
adapter
=
GetFormatter
(
connection
);
for
(
var
i
=
0
;
i
<
nonIdProps
.
Count
;
i
++)
{
var
property
=
nonIdProps
.
ElementAt
(
i
);
sb
.
AppendFormat
(
"{0} = @{1}"
,
property
.
Name
,
property
.
Name
);
adapter
.
AppendColumnNameEqualsValue
(
sb
,
property
.
Name
);
if
(
i
<
nonIdProps
.
Count
-
1
)
sb
.
AppendFormat
(
", "
);
}
...
...
@@ -222,7 +223,7 @@ public static partial class SqlMapperExtensions
for
(
var
i
=
0
;
i
<
keyProperties
.
Count
;
i
++)
{
var
property
=
keyProperties
.
ElementAt
(
i
);
sb
.
AppendFormat
(
"{0} = @{1}"
,
property
.
Name
,
property
.
Name
);
adapter
.
AppendColumnNameEqualsValue
(
sb
,
property
.
Name
);
if
(
i
<
keyProperties
.
Count
-
1
)
sb
.
AppendFormat
(
" and "
);
}
...
...
@@ -348,12 +349,12 @@ public partial class MySqlAdapter
var
id
=
r
.
First
().
id
;
if
(
id
==
null
)
return
0
;
var
pi
=
keyProperties
as
PropertyInfo
[]
??
keyProperties
.
ToArray
();
if
(!
pi
.
Any
())
return
id
;
if
(!
pi
.
Any
())
return
Convert
.
ToInt32
(
id
)
;
var
idp
=
pi
.
First
();
idp
.
SetValue
(
entityToInsert
,
Convert
.
ChangeType
(
id
,
idp
.
PropertyType
),
null
);
return
(
int
)
id
;
return
Convert
.
ToInt32
(
id
)
;
}
}
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
8c7a14cd
...
...
@@ -42,6 +42,7 @@ public interface ITableNameMapper
private
static
readonly
ConcurrentDictionary
<
RuntimeTypeHandle
,
string
>
GetQueries
=
new
ConcurrentDictionary
<
RuntimeTypeHandle
,
string
>();
private
static
readonly
ConcurrentDictionary
<
RuntimeTypeHandle
,
string
>
TypeTableName
=
new
ConcurrentDictionary
<
RuntimeTypeHandle
,
string
>();
private
static
readonly
ISqlAdapter
DefaultAdapter
=
new
SqlServerAdapter
();
private
static
readonly
Dictionary
<
string
,
ISqlAdapter
>
AdapterDictionary
=
new
Dictionary
<
string
,
ISqlAdapter
>
{
...
...
@@ -466,15 +467,14 @@ private static string GetTableName(Type type)
/// </summary>
public
static
GetDatabaseTypeDelegate
GetDatabaseType
;
private
static
ISqlAdapter
GetFormatter
(
IDbConnection
connection
)
{
var
name
=
GetDatabaseType
?.
Invoke
(
connection
).
ToLower
()
??
connection
.
GetType
().
Name
.
ToLower
();
return
!
AdapterDictionary
.
ContainsKey
(
name
)
?
new
SqlServerAdapter
()
:
AdapterDictionary
[
name
];
return
!
AdapterDictionary
.
ContainsKey
(
name
)
?
DefaultAdapter
:
AdapterDictionary
[
name
];
}
static
class
ProxyGenerator
...
...
@@ -754,12 +754,12 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
var
id
=
r
.
First
().
id
;
if
(
id
==
null
)
return
0
;
var
propertyInfos
=
keyProperties
as
PropertyInfo
[]
??
keyProperties
.
ToArray
();
if
(!
propertyInfos
.
Any
())
return
id
;
if
(!
propertyInfos
.
Any
())
return
Convert
.
ToInt32
(
id
)
;
var
idp
=
propertyInfos
.
First
();
idp
.
SetValue
(
entityToInsert
,
Convert
.
ChangeType
(
id
,
idp
.
PropertyType
),
null
);
return
(
int
)
id
;
return
Convert
.
ToInt32
(
id
)
;
}
public
void
AppendColumnName
(
StringBuilder
sb
,
string
columnName
)
...
...
Dapper.Tests.Contrib/TestSuite.Async.cs
View file @
8c7a14cd
...
...
@@ -235,7 +235,6 @@ public async Task UpdateListAsync()
var
name
=
connection
.
Query
<
User
>(
"select * from users"
).
First
().
Name
;
name
.
Contains
(
"updated"
).
IsTrue
();
}
}
[
Fact
]
...
...
@@ -261,7 +260,6 @@ public async Task DeleteListAsync()
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
-
10
);
}
}
[
Fact
]
...
...
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