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
a967b0c2
Commit
a967b0c2
authored
Dec 25, 2015
by
joncloud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added checks to make sure that arrays get the appropriate type when delete/insert/update is called.
parent
fa03d54b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
17 deletions
+122
-17
SqlMapperExtensions.Async.cs
Dapper.Contrib/SqlMapperExtensions.Async.cs
+20
-3
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+20
-3
TestSuite.Async.cs
Dapper.Tests.Contrib/TestSuite.Async.cs
+41
-5
TestSuite.cs
Dapper.Tests.Contrib/TestSuite.cs
+41
-6
No files found.
Dapper.Contrib/SqlMapperExtensions.Async.cs
View file @
a967b0c2
...
...
@@ -135,7 +135,12 @@ public static partial class SqlMapperExtensions
sqlAdapter
=
GetFormatter
(
connection
);
var
isList
=
false
;
if
(
type
.
IsArray
||
type
.
IsGenericType
())
if
(
type
.
IsArray
)
{
isList
=
true
;
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
isList
=
true
;
type
=
type
.
GetGenericArguments
()[
0
];
...
...
@@ -195,8 +200,14 @@ public static partial class SqlMapperExtensions
var
type
=
typeof
(
T
);
if
(
type
.
IsArray
||
type
.
IsGenericType
())
if
(
type
.
IsArray
)
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
type
=
type
.
GetGenericArguments
()[
0
];
}
var
keyProperties
=
KeyPropertiesCache
(
type
);
var
explicitKeyProperties
=
ExplicitKeyPropertiesCache
(
type
);
...
...
@@ -250,8 +261,14 @@ public static partial class SqlMapperExtensions
var
type
=
typeof
(
T
);
if
(
type
.
IsArray
||
type
.
IsGenericType
())
if
(
type
.
IsArray
)
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
type
=
type
.
GetGenericArguments
()[
0
];
}
var
keyProperties
=
KeyPropertiesCache
(
type
);
var
explicitKeyProperties
=
ExplicitKeyPropertiesCache
(
type
);
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
a967b0c2
...
...
@@ -295,7 +295,12 @@ private static string GetTableName(Type type)
var
type
=
typeof
(
T
);
if
(
type
.
IsArray
||
type
.
IsGenericType
())
if
(
type
.
IsArray
)
{
isList
=
true
;
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
isList
=
true
;
type
=
type
.
GetGenericArguments
()[
0
];
...
...
@@ -365,8 +370,14 @@ private static string GetTableName(Type type)
var
type
=
typeof
(
T
);
if
(
type
.
IsArray
||
type
.
IsGenericType
())
if
(
type
.
IsArray
)
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
type
=
type
.
GetGenericArguments
()[
0
];
}
var
keyProperties
=
KeyPropertiesCache
(
type
).
ToList
();
//added ToList() due to issue #418, must work on a list copy
var
explicitKeyProperties
=
ExplicitKeyPropertiesCache
(
type
);
...
...
@@ -420,8 +431,14 @@ private static string GetTableName(Type type)
var
type
=
typeof
(
T
);
if
(
type
.
IsArray
||
type
.
IsGenericType
())
if
(
type
.
IsArray
)
{
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
type
=
type
.
GetGenericArguments
()[
0
];
}
var
keyProperties
=
KeyPropertiesCache
(
type
).
ToList
();
//added ToList() due to issue #418, must work on a list copy
var
explicitKeyProperties
=
ExplicitKeyPropertiesCache
(
type
);
...
...
Dapper.Tests.Contrib/TestSuite.Async.cs
View file @
a967b0c2
...
...
@@ -194,8 +194,20 @@ public async Task BuilderTemplateWithoutCompositionAsync()
}
}
[
Fact
]
public
async
Task
InsertArrayAsync
()
{
await
InsertHelperAsync
(
src
=>
src
.
ToArray
());
}
[
Fact
]
public
async
Task
InsertListAsync
()
{
await
InsertHelperAsync
(
src
=>
src
.
ToList
());
}
private
async
Task
InsertHelperAsync
<
T
>(
Func
<
IEnumerable
<
User
>,
T
>
helper
)
where
T
:
class
{
const
int
numberOfEntities
=
10
;
...
...
@@ -207,15 +219,27 @@ public async Task InsertListAsync()
{
await
connection
.
DeleteAllAsync
<
User
>();
var
total
=
await
connection
.
InsertAsync
(
users
);
var
total
=
await
connection
.
InsertAsync
(
helper
(
users
)
);
total
.
IsEqualTo
(
numberOfEntities
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
);
}
}
[
Fact
]
public
async
Task
UpdateArrayAsync
()
{
await
UpdateHelperAsync
(
src
=>
src
.
ToArray
());
}
[
Fact
]
public
async
Task
UpdateListAsync
()
{
await
UpdateHelperAsync
(
src
=>
src
.
ToList
());
}
private
async
Task
UpdateHelperAsync
<
T
>(
Func
<
IEnumerable
<
User
>,
T
>
helper
)
where
T
:
class
{
const
int
numberOfEntities
=
10
;
...
...
@@ -227,7 +251,7 @@ public async Task UpdateListAsync()
{
await
connection
.
DeleteAllAsync
<
User
>();
var
total
=
await
connection
.
InsertAsync
(
users
);
var
total
=
await
connection
.
InsertAsync
(
helper
(
users
)
);
total
.
IsEqualTo
(
numberOfEntities
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
);
...
...
@@ -235,14 +259,26 @@ public async Task UpdateListAsync()
{
user
.
Name
=
user
.
Name
+
" updated"
;
}
await
connection
.
UpdateAsync
(
users
);
await
connection
.
UpdateAsync
(
helper
(
users
)
);
var
name
=
connection
.
Query
<
User
>(
"select * from users"
).
First
().
Name
;
name
.
Contains
(
"updated"
).
IsTrue
();
}
}
[
Fact
]
public
async
Task
DeleteArrayAsync
()
{
await
DeleteHelperAsync
(
src
=>
src
.
ToArray
());
}
[
Fact
]
public
async
Task
DeleteListAsync
()
{
await
DeleteHelperAsync
(
src
=>
src
.
ToList
());
}
private
async
Task
DeleteHelperAsync
<
T
>(
Func
<
IEnumerable
<
User
>,
T
>
helper
)
where
T
:
class
{
const
int
numberOfEntities
=
10
;
...
...
@@ -254,13 +290,13 @@ public async Task DeleteListAsync()
{
await
connection
.
DeleteAllAsync
<
User
>();
var
total
=
await
connection
.
InsertAsync
(
users
);
var
total
=
await
connection
.
InsertAsync
(
helper
(
users
)
);
total
.
IsEqualTo
(
numberOfEntities
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
);
var
usersToDelete
=
users
.
Take
(
10
).
ToList
();
await
connection
.
DeleteAsync
(
usersToDelete
);
await
connection
.
DeleteAsync
(
helper
(
usersToDelete
)
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
-
10
);
}
...
...
Dapper.Tests.Contrib/TestSuite.cs
View file @
a967b0c2
...
...
@@ -280,8 +280,20 @@ public void TestClosedConnection()
}
}
[
Fact
]
public
void
InsertArray
()
{
InsertHelper
(
src
=>
src
.
ToArray
());
}
[
Fact
]
public
void
InsertList
()
{
InsertHelper
(
src
=>
src
.
ToList
());
}
private
void
InsertHelper
<
T
>(
Func
<
IEnumerable
<
User
>,
T
>
helper
)
where
T
:
class
{
const
int
numberOfEntities
=
10
;
...
...
@@ -293,15 +305,27 @@ public void InsertList()
{
connection
.
DeleteAll
<
User
>();
var
total
=
connection
.
Insert
(
users
);
var
total
=
connection
.
Insert
(
helper
(
users
)
);
total
.
IsEqualTo
(
numberOfEntities
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
);
}
}
[
Fact
]
public
void
UpdateArray
()
{
UpdateHelper
(
src
=>
src
.
ToArray
());
}
[
Fact
]
public
void
UpdateList
()
{
UpdateHelper
(
src
=>
src
.
ToList
());
}
private
void
UpdateHelper
<
T
>(
Func
<
IEnumerable
<
User
>,
T
>
helper
)
where
T
:
class
{
const
int
numberOfEntities
=
10
;
...
...
@@ -313,7 +337,7 @@ public void UpdateList()
{
connection
.
DeleteAll
<
User
>();
var
total
=
connection
.
Insert
(
users
);
var
total
=
connection
.
Insert
(
helper
(
users
)
);
total
.
IsEqualTo
(
numberOfEntities
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
);
...
...
@@ -321,14 +345,26 @@ public void UpdateList()
{
user
.
Name
=
user
.
Name
+
" updated"
;
}
connection
.
Update
(
users
);
connection
.
Update
(
helper
(
users
)
);
var
name
=
connection
.
Query
<
User
>(
"select * from users"
).
First
().
Name
;
name
.
Contains
(
"updated"
).
IsTrue
();
}
}
[
Fact
]
public
void
DeleteArray
()
{
DeleteHelper
(
src
=>
src
.
ToArray
());
}
[
Fact
]
public
void
DeleteList
()
{
DeleteHelper
(
src
=>
src
.
ToList
());
}
private
void
DeleteHelper
<
T
>(
Func
<
IEnumerable
<
User
>,
T
>
helper
)
where
T
:
class
{
const
int
numberOfEntities
=
10
;
...
...
@@ -340,17 +376,16 @@ public void DeleteList()
{
connection
.
DeleteAll
<
User
>();
var
total
=
connection
.
Insert
(
users
);
var
total
=
connection
.
Insert
(
helper
(
users
)
);
total
.
IsEqualTo
(
numberOfEntities
);
users
=
connection
.
Query
<
User
>(
"select * from users"
).
ToList
();
users
.
Count
.
IsEqualTo
(
numberOfEntities
);
var
usersToDelete
=
users
.
Take
(
10
).
ToList
();
connection
.
Delete
(
usersToDelete
);
connection
.
Delete
(
helper
(
usersToDelete
)
);
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