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
6799063c
Commit
6799063c
authored
Mar 05, 2012
by
vosen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for multimapping with constructors.
parent
00e7d708
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
Tests.cs
Tests/Tests.cs
+55
-0
No files found.
Tests/Tests.cs
View file @
6799063c
...
@@ -33,6 +33,61 @@ public class ConcreteOrder : Order
...
@@ -33,6 +33,61 @@ public class ConcreteOrder : Order
}
}
}
}
class
UserWithConstructor
{
public
UserWithConstructor
(
int
id
,
string
name
)
{
Ident
=
id
;
FullName
=
name
;
}
public
int
Ident
{
get
;
set
;
}
public
string
FullName
{
get
;
set
;
}
}
class
PostWithConstructor
{
public
PostWithConstructor
(
int
id
,
int
ownerid
,
string
content
)
{
Ident
=
id
;
FullContent
=
content
;
}
public
int
Ident
{
get
;
set
;
}
public
UserWithConstructor
Owner
{
get
;
set
;
}
public
string
FullContent
{
get
;
set
;
}
public
Comment
Comment
{
get
;
set
;
}
}
public
void
TestMultiMapWithConstructor
()
{
var
createSql
=
@"
create table #Users (Id int, Name varchar(20))
create table #Posts (Id int, OwnerId int, Content varchar(20))
insert #Users values(99, 'Sam')
insert #Users values(2, 'I am')
insert #Posts values(1, 99, 'Sams Post1')
insert #Posts values(2, 99, 'Sams Post2')
insert #Posts values(3, null, 'no ones post')"
;
connection
.
Execute
(
createSql
);
string
sql
=
@"select * from #Posts p
left join #Users u on u.Id = p.OwnerId
Order by p.Id"
;
PostWithConstructor
[]
data
=
connection
.
Query
<
PostWithConstructor
,
UserWithConstructor
,
PostWithConstructor
>(
sql
,
(
post
,
user
)
=>
{
post
.
Owner
=
user
;
return
post
;}).
ToArray
();
var
p
=
data
.
First
();
p
.
FullContent
.
IsEqualTo
(
"Sams Post1"
);
p
.
Ident
.
IsEqualTo
(
1
);
p
.
Owner
.
FullName
.
IsEqualTo
(
"Sam"
);
p
.
Owner
.
Ident
.
IsEqualTo
(
99
);
data
[
2
].
Owner
.
IsNull
();
connection
.
Execute
(
"drop table #Users drop table #Posts"
);
}
class
MultipleConstructors
class
MultipleConstructors
{
{
public
MultipleConstructors
()
public
MultipleConstructors
()
...
...
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