Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Dapper
提交
c7ed6ec7
D
Dapper
项目概览
int
/
Dapper
大约 1 年 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dapper
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7ed6ec7
编写于
5月 27, 2016
作者:
M
Marc Gravell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #524 - `GridReader` should use the same conversion code as the regular reader
上级
c3beb607
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
22 addition
and
8 deletion
+22
-8
Dapper.Tests/Tests.QueryMultiple.cs
Dapper.Tests/Tests.QueryMultiple.cs
+1
-1
Dapper/SqlMapper.GridReader.Async.cs
Dapper/SqlMapper.GridReader.Async.cs
+1
-1
Dapper/SqlMapper.GridReader.cs
Dapper/SqlMapper.GridReader.cs
+20
-6
未找到文件。
Dapper.Tests/Tests.QueryMultiple.cs
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录