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
39b1fd5a
Commit
39b1fd5a
authored
Apr 23, 2018
by
Brian Drupieski
Committed by
Nick Craver
May 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IEnumerable<T> check when updating and deleting
parent
f29981a7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
4 deletions
+134
-4
SqlMapperExtensions.Async.cs
Dapper.Contrib/SqlMapperExtensions.Async.cs
+18
-2
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+18
-2
TestSuite.Async.cs
Dapper.Tests.Contrib/TestSuite.Async.cs
+49
-0
TestSuite.cs
Dapper.Tests.Contrib/TestSuite.cs
+49
-0
No files found.
Dapper.Contrib/SqlMapperExtensions.Async.cs
View file @
39b1fd5a
...
...
@@ -220,9 +220,17 @@ public static partial class SqlMapperExtensions
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
{
type
=
type
.
GetGenericArguments
()[
0
];
}
}
var
keyProperties
=
KeyPropertiesCache
(
type
);
var
explicitKeyProperties
=
ExplicitKeyPropertiesCache
(
type
);
...
...
@@ -281,9 +289,17 @@ public static partial class SqlMapperExtensions
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
{
type
=
type
.
GetGenericArguments
()[
0
];
}
}
var
keyProperties
=
KeyPropertiesCache
(
type
);
var
explicitKeyProperties
=
ExplicitKeyPropertiesCache
(
type
);
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
39b1fd5a
...
...
@@ -414,9 +414,17 @@ private static string GetTableName(Type type)
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
{
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
);
...
...
@@ -475,9 +483,17 @@ private static string GetTableName(Type type)
type
=
type
.
GetElementType
();
}
else
if
(
type
.
IsGenericType
())
{
var
typeInfo
=
type
.
GetTypeInfo
();
bool
implementsGenericIEnumerableOrIsGenericIEnumerable
=
typeInfo
.
ImplementedInterfaces
.
Any
(
ti
=>
ti
.
IsGenericType
()
&&
ti
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>))
||
typeInfo
.
GetGenericTypeDefinition
()
==
typeof
(
IEnumerable
<>);
if
(
implementsGenericIEnumerableOrIsGenericIEnumerable
)
{
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 @
39b1fd5a
...
...
@@ -46,6 +46,43 @@ public async Task TypeWithGenericParameterCanBeInsertedAsync()
}
}
[
Fact
]
public
async
Task
TypeWithGenericParameterCanBeUpdatedAsync
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
objectToInsert
=
new
GenericType
<
string
>
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"something"
};
await
connection
.
InsertAsync
(
objectToInsert
);
objectToInsert
.
Name
=
"somethingelse"
;
await
connection
.
UpdateAsync
(
objectToInsert
);
var
updatedObject
=
connection
.
Get
<
GenericType
<
string
>>(
objectToInsert
.
Id
);
Assert
.
Equal
(
objectToInsert
.
Name
,
updatedObject
.
Name
);
}
}
[
Fact
]
public
async
Task
TypeWithGenericParameterCanBeDeletedAsync
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
objectToInsert
=
new
GenericType
<
string
>
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"something"
};
await
connection
.
InsertAsync
(
objectToInsert
);
bool
deleted
=
await
connection
.
DeleteAsync
(
objectToInsert
);
Assert
.
True
(
deleted
);
}
}
/// <summary>
/// Tests for issue #351
/// </summary>
...
...
@@ -263,6 +300,12 @@ private async Task InsertHelperAsync<T>(Func<IEnumerable<User>, T> helper)
}
}
[
Fact
]
public
async
Task
UpdateEnumerableAsync
()
{
await
UpdateHelperAsync
(
src
=>
src
.
AsEnumerable
()).
ConfigureAwait
(
false
);
}
[
Fact
]
public
async
Task
UpdateArrayAsync
()
{
...
...
@@ -302,6 +345,12 @@ private async Task UpdateHelperAsync<T>(Func<IEnumerable<User>, T> helper)
}
}
[
Fact
]
public
async
Task
DeleteEnumerableAsync
()
{
await
DeleteHelperAsync
(
src
=>
src
.
AsEnumerable
()).
ConfigureAwait
(
false
);
}
[
Fact
]
public
async
Task
DeleteArrayAsync
()
{
...
...
Dapper.Tests.Contrib/TestSuite.cs
View file @
39b1fd5a
...
...
@@ -154,6 +154,43 @@ public void TypeWithGenericParameterCanBeInserted()
}
}
[
Fact
]
public
void
TypeWithGenericParameterCanBeUpdated
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
objectToInsert
=
new
GenericType
<
string
>
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"something"
};
connection
.
Insert
(
objectToInsert
);
objectToInsert
.
Name
=
"somethingelse"
;
connection
.
Update
(
objectToInsert
);
var
updatedObject
=
connection
.
Get
<
GenericType
<
string
>>(
objectToInsert
.
Id
);
Assert
.
Equal
(
objectToInsert
.
Name
,
updatedObject
.
Name
);
}
}
[
Fact
]
public
void
TypeWithGenericParameterCanBeDeleted
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
objectToInsert
=
new
GenericType
<
string
>
{
Id
=
Guid
.
NewGuid
().
ToString
(),
Name
=
"something"
};
connection
.
Insert
(
objectToInsert
);
bool
deleted
=
connection
.
Delete
(
objectToInsert
);
Assert
.
True
(
deleted
);
}
}
[
Fact
]
public
void
Issue418
()
{
...
...
@@ -362,6 +399,12 @@ private void InsertHelper<T>(Func<IEnumerable<User>, T> helper)
}
}
[
Fact
]
public
void
UpdateEnumerable
()
{
UpdateHelper
(
src
=>
src
.
AsEnumerable
());
}
[
Fact
]
public
void
UpdateArray
()
{
...
...
@@ -401,6 +444,12 @@ private void UpdateHelper<T>(Func<IEnumerable<User>, T> helper)
}
}
[
Fact
]
public
void
DeleteEnumerable
()
{
DeleteHelper
(
src
=>
src
.
AsEnumerable
());
}
[
Fact
]
public
void
DeleteArray
()
{
...
...
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