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
c7ed6ec7
Commit
c7ed6ec7
authored
May 27, 2016
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #524 - `GridReader` should use the same conversion code as the regular reader
parent
c3beb607
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
8 deletions
+22
-8
Tests.QueryMultiple.cs
Dapper.Tests/Tests.QueryMultiple.cs
+1
-1
SqlMapper.GridReader.Async.cs
Dapper/SqlMapper.GridReader.Async.cs
+1
-1
SqlMapper.GridReader.cs
Dapper/SqlMapper.GridReader.cs
+20
-6
No files found.
Dapper.Tests/Tests.QueryMultiple.cs
View file @
c7ed6ec7
...
...
@@ -141,7 +141,7 @@ public void Issue524_QueryMultiple_Cast()
{
// aka: Read<int> should work even if the data is a <long>
// using regular API
connection
.
Query
<
int
>(
"select cast(42 as bigint)"
).
IsEqualTo
(
42
);
connection
.
Query
<
int
>(
"select cast(42 as bigint)"
).
Single
().
IsEqualTo
(
42
);
connection
.
QuerySingle
<
int
>(
"select cast(42 as bigint)"
).
IsEqualTo
(
42
);
// using multi-reader API
...
...
Dapper/SqlMapper.GridReader.Async.cs
View file @
c7ed6ec7
...
...
@@ -181,7 +181,7 @@ private Task<IEnumerable<T>> ReadAsyncImpl<T>(Type type, bool buffered)
}
else
{
var
result
=
ReadDeferred
<
T
>(
gridIndex
,
deserializer
.
Func
,
typedIdentity
);
var
result
=
ReadDeferred
<
T
>(
gridIndex
,
deserializer
.
Func
,
typedIdentity
,
type
);
if
(
buffered
)
result
=
result
.
ToList
();
// for the "not a DbDataReader" scenario
return
Task
.
FromResult
(
result
);
}
...
...
Dapper/SqlMapper.GridReader.cs
View file @
c7ed6ec7
...
...
@@ -2,7 +2,7 @@
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
using
System.Globalization
;
namespace
Dapper
{
partial
class
SqlMapper
...
...
@@ -161,7 +161,7 @@ private IEnumerable<T> ReadImpl<T>(Type type, bool buffered)
cache
.
Deserializer
=
deserializer
;
}
IsConsumed
=
true
;
var
result
=
ReadDeferred
<
T
>(
gridIndex
,
deserializer
.
Func
,
typedIdentity
);
var
result
=
ReadDeferred
<
T
>(
gridIndex
,
deserializer
.
Func
,
typedIdentity
,
type
);
return
buffered
?
result
.
ToList
()
:
result
;
}
...
...
@@ -184,8 +184,16 @@ private T ReadRow<T>(Type type, Row row)
deserializer
=
new
DeserializerState
(
hash
,
GetDeserializer
(
type
,
reader
,
0
,
-
1
,
false
));
cache
.
Deserializer
=
deserializer
;
}
result
=
(
T
)
deserializer
.
Func
(
reader
);
if
((
row
&
Row
.
Single
)
!=
0
&&
reader
.
Read
())
ThrowMultipleRows
(
row
);
while
(
reader
.
Read
())
{
}
object
val
=
deserializer
.
Func
(
reader
);
if
(
val
==
null
||
val
is
T
)
{
result
=
(
T
)
val
;
}
else
{
var
convertToType
=
Nullable
.
GetUnderlyingType
(
type
)
??
type
;
result
=
(
T
)
Convert
.
ChangeType
(
val
,
convertToType
,
CultureInfo
.
InvariantCulture
);
}
if
((
row
&
Row
.
Single
)
!=
0
&&
reader
.
Read
())
ThrowMultipleRows
(
row
);
while
(
reader
.
Read
())
{
}
}
else
if
((
row
&
Row
.
FirstOrDefault
)
==
0
)
// demanding a row, and don't have one
{
...
...
@@ -297,13 +305,19 @@ public IEnumerable<TReturn> Read<TReturn>(Type[] types, Func<object[], TReturn>
return
buffered
?
result
.
ToList
()
:
result
;
}
private
IEnumerable
<
T
>
ReadDeferred
<
T
>(
int
index
,
Func
<
IDataReader
,
object
>
deserializer
,
Identity
typedIdentity
)
private
IEnumerable
<
T
>
ReadDeferred
<
T
>(
int
index
,
Func
<
IDataReader
,
object
>
deserializer
,
Identity
typedIdentity
,
Type
effectiveType
)
{
try
{
var
convertToType
=
Nullable
.
GetUnderlyingType
(
effectiveType
)
??
effectiveType
;
while
(
index
==
gridIndex
&&
reader
.
Read
())
{
yield
return
(
T
)
deserializer
(
reader
);
object
val
=
deserializer
(
reader
);
if
(
val
==
null
||
val
is
T
)
{
yield
return
(
T
)
val
;
}
else
{
yield
return
(
T
)
Convert
.
ChangeType
(
val
,
convertToType
,
CultureInfo
.
InvariantCulture
);
}
}
}
finally
// finally so that First etc progresses things even when multiple rows
...
...
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