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
37b45caf
Commit
37b45caf
authored
May 14, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more flexible multi mapping ...
parent
3ddbd667
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
10 deletions
+65
-10
SqlMapper.cs
Dapper/SqlMapper.cs
+9
-1
Tests.cs
Tests/Tests.cs
+56
-9
No files found.
Dapper/SqlMapper.cs
View file @
37b45caf
...
@@ -270,13 +270,21 @@ class DontMap {}
...
@@ -270,13 +270,21 @@ class DontMap {}
{
{
int
current
=
0
;
int
current
=
0
;
var
splits
=
splitOn
.
Split
(
','
).
ToArray
();
var
splitIndex
=
0
;
Func
<
int
>
nextSplit
=
()
=>
Func
<
int
>
nextSplit
=
()
=>
{
{
var
currentSplit
=
splits
[
splitIndex
];
if
(
splits
.
Length
>
splitIndex
+
1
)
{
splitIndex
++;
}
int
pos
;
int
pos
;
for
(
pos
=
current
+
1
;
pos
<
reader
.
FieldCount
;
pos
++)
for
(
pos
=
current
+
1
;
pos
<
reader
.
FieldCount
;
pos
++)
{
{
// some people like ID some id ... assuming case insensitive splits for now
// some people like ID some id ... assuming case insensitive splits for now
if
(
string
.
Equals
(
reader
.
GetName
(
pos
),
splitOn
,
StringComparison
.
InvariantCultureIgnoreCase
))
if
(
string
.
Equals
(
reader
.
GetName
(
pos
),
currentSplit
,
StringComparison
.
InvariantCultureIgnoreCase
))
{
{
break
;
break
;
}
}
...
...
Tests/Tests.cs
View file @
37b45caf
...
@@ -39,7 +39,7 @@ public static void IsFalse(this bool b)
...
@@ -39,7 +39,7 @@ public static void IsFalse(this bool b)
public
static
void
IsTrue
(
this
bool
b
)
public
static
void
IsTrue
(
this
bool
b
)
{
{
if
(
b
)
if
(
!
b
)
{
{
throw
new
ApplicationException
(
"Expected true"
);
throw
new
ApplicationException
(
"Expected true"
);
}
}
...
@@ -203,18 +203,22 @@ public void TestSetPrivate()
...
@@ -203,18 +203,22 @@ public void TestSetPrivate()
public
void
TestEnumeration
()
public
void
TestEnumeration
()
{
{
var
en
=
connection
.
Query
<
int
>(
"select 1 as one"
,
buffered
:
false
);
var
en
=
connection
.
Query
<
int
>(
"select 1 as one union all select 2 as one"
,
buffered
:
false
);
var
i
=
en
.
GetEnumerator
();
i
.
MoveNext
();
bool
gotException
=
false
;
bool
gotException
=
false
;
try
try
{
{
connection
.
Query
<
int
>(
"select 1 as one"
,
buffered
:
false
);
var
x
=
connection
.
Query
<
int
>(
"select 1 as one"
,
buffered
:
false
).
First
(
);
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
gotException
=
true
;
gotException
=
true
;
}
}
var
realItems
=
en
.
ToList
();
while
(
i
.
MoveNext
())
{
}
// should not exception, since enumertated
// should not exception, since enumertated
en
=
connection
.
Query
<
int
>(
"select 1 as one"
,
buffered
:
false
);
en
=
connection
.
Query
<
int
>(
"select 1 as one"
,
buffered
:
false
);
...
@@ -224,22 +228,25 @@ public void TestEnumeration()
...
@@ -224,22 +228,25 @@ public void TestEnumeration()
public
void
TestEnumerationDynamic
()
public
void
TestEnumerationDynamic
()
{
{
var
en
=
connection
.
Query
(
"select 1 as one"
,
buffered
:
false
);
var
en
=
connection
.
Query
(
"select 1 as one union all select 2 as one"
,
buffered
:
false
);
var
i
=
en
.
GetEnumerator
();
i
.
MoveNext
();
bool
gotException
=
false
;
bool
gotException
=
false
;
try
try
{
{
connection
.
Query
(
"select 1 as one"
,
buffered
:
false
);
var
x
=
connection
.
Query
(
"select 1 as one"
,
buffered
:
false
).
First
(
);
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
gotException
=
true
;
gotException
=
true
;
}
}
int
i
=
en
.
First
().
one
;
while
(
i
.
MoveNext
())
i
.
IsEqualTo
(
1
);
{
}
// should not exception, since enumertated
// should not exception, since enumertated
en
=
connection
.
Query
(
"select 1 as one"
,
buffered
:
false
);
en
=
connection
.
Query
(
"select 1 as one"
,
buffered
:
false
);
gotException
.
IsTrue
();
gotException
.
IsTrue
();
}
}
...
@@ -531,6 +538,46 @@ select 1111
...
@@ -531,6 +538,46 @@ select 1111
}
}
class
Person
{
public
int
PersonId
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
class
Address
{
public
int
AddressId
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
int
PersonId
{
get
;
set
;
}
}
class
Extra
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
public
void
TestFlexibleMultiMapping
()
{
var
sql
=
@"select
1 as PersonId, 'bob' as Name,
2 as AddressId, 'abc street' as Name, 1 as PersonId,
3 as Id, 'fred' as Name
"
;
var
personWithAddress
=
connection
.
Query
<
Person
,
Address
,
Extra
,
Tuple
<
Person
,
Address
,
Extra
>>
(
sql
,
(
p
,
a
,
e
)
=>
Tuple
.
Create
(
p
,
a
,
e
),
splitOn
:
"AddressId,Id"
).
First
();
personWithAddress
.
Item1
.
PersonId
.
IsEqualTo
(
1
);
personWithAddress
.
Item1
.
Name
.
IsEqualTo
(
"bob"
);
personWithAddress
.
Item2
.
AddressId
.
IsEqualTo
(
2
);
personWithAddress
.
Item2
.
Name
.
IsEqualTo
(
"abc street"
);
personWithAddress
.
Item2
.
PersonId
.
IsEqualTo
(
1
);
personWithAddress
.
Item3
.
Id
.
IsEqualTo
(
3
);
personWithAddress
.
Item3
.
Name
.
IsEqualTo
(
"fred"
);
}
/* TODO:
/* TODO:
*
*
public void TestMagicParam()
public void TestMagicParam()
...
...
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