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
304d2b00
Commit
304d2b00
authored
Jul 13, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve error message when multi mapper is misused
parent
e4b05097
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
SqlMapper.cs
Dapper/SqlMapper.cs
+13
-1
Tests.cs
Tests/Tests.cs
+20
-0
No files found.
Dapper/SqlMapper.cs
View file @
304d2b00
...
@@ -804,9 +804,15 @@ IEnumerator IEnumerable.GetEnumerator()
...
@@ -804,9 +804,15 @@ IEnumerator IEnumerable.GetEnumerator()
private
static
Func
<
IDataReader
,
T
>
GetDynamicDeserializer
<
T
>(
IDataRecord
reader
,
int
startBound
,
int
length
,
bool
returnNullIfFirstMissing
)
private
static
Func
<
IDataReader
,
T
>
GetDynamicDeserializer
<
T
>(
IDataRecord
reader
,
int
startBound
,
int
length
,
bool
returnNullIfFirstMissing
)
{
{
var
fieldCount
=
reader
.
FieldCount
;
if
(
length
==
-
1
)
if
(
length
==
-
1
)
{
{
length
=
reader
.
FieldCount
-
startBound
;
length
=
fieldCount
-
startBound
;
}
if
(
fieldCount
<=
startBound
)
{
throw
new
ArgumentException
(
"When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id"
,
"splitOn"
);
}
}
return
return
...
@@ -1143,7 +1149,13 @@ static readonly MethodInfo
...
@@ -1143,7 +1149,13 @@ static readonly MethodInfo
length
=
reader
.
FieldCount
-
startBound
;
length
=
reader
.
FieldCount
-
startBound
;
}
}
if
(
reader
.
FieldCount
<=
startBound
)
{
throw
new
ArgumentException
(
"When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id"
,
"splitOn"
);
}
var
names
=
new
List
<
string
>();
var
names
=
new
List
<
string
>();
for
(
int
i
=
startBound
;
i
<
startBound
+
length
;
i
++)
for
(
int
i
=
startBound
;
i
<
startBound
+
length
;
i
++)
{
{
names
.
Add
(
reader
.
GetName
(
i
));
names
.
Add
(
reader
.
GetName
(
i
));
...
...
Tests/Tests.cs
View file @
304d2b00
...
@@ -958,5 +958,25 @@ public void TestNullableCharInputAndOutputNull()
...
@@ -958,5 +958,25 @@ public void TestNullableCharInputAndOutputNull()
obj
.
ValueNullable
.
IsEqualTo
(
test
);
obj
.
ValueNullable
.
IsEqualTo
(
test
);
}
}
public
void
TestInvalidSplitCausesNiceError
()
{
try
{
connection
.
Query
<
User
,
User
,
User
>(
"select 1 A, 2 B, 3 C"
,
(
x
,
y
)
=>
x
);
}
catch
(
ArgumentException
)
{
// expecting an app exception due to multi mapping being bodged
}
try
{
connection
.
Query
<
dynamic
,
dynamic
,
dynamic
>(
"select 1 A, 2 B, 3 C"
,
(
x
,
y
)
=>
x
);
}
catch
(
ArgumentException
)
{
// expecting an app exception due to multi mapping being bodged
}
}
}
}
}
}
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