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
6ce36492
Commit
6ce36492
authored
Aug 21, 2017
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README for new assertions
parent
4e99985d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
29 deletions
+18
-29
Readme.md
Readme.md
+18
-29
No files found.
Readme.md
View file @
6ce36492
...
...
@@ -36,14 +36,9 @@ public class Dog
var
guid
=
Guid
.
NewGuid
();
var
dog
=
connection
.
Query
<
Dog
>(
"select Age = @Age, Id = @Id"
,
new
{
Age
=
(
int
?)
null
,
Id
=
guid
});
dog
.
Count
()
.
IsEqualTo
(
1
);
dog
.
First
().
Age
.
IsNull
();
dog
.
First
().
Id
.
IsEqualTo
(
guid
);
Assert
.
Equal
(
1
,
dog
.
Count
());
Assert
.
Null
(
dog
.
First
().
Age
);
Assert
.
Equal
(
guid
,
dog
.
First
().
Id
);
```
Execute a query and map it to a list of dynamic objects
...
...
@@ -59,17 +54,10 @@ Example usage:
```
csharp
var
rows
=
connection
.
Query
(
"select 1 A, 2 B union all select 3, 4"
);
((
int
)
rows
[
0
].
A
)
.
IsEqualTo
(
1
);
((
int
)
rows
[
0
].
B
)
.
IsEqualTo
(
2
);
((
int
)
rows
[
1
].
A
)
.
IsEqualTo
(
3
);
((
int
)
rows
[
1
].
B
)
.
IsEqualTo
(
4
);
Assert
.
Equal
(
1
,
(
int
)
rows
[
0
].
A
);
Assert
.
Equal
(
2
,
(
int
)
rows
[
0
].
B
);
Assert
.
Equal
(
3
,
(
int
)
rows
[
1
].
A
);
Assert
.
Equal
(
4
,
(
int
)
rows
[
1
].
B
);
```
Execute a Command that returns no results
...
...
@@ -82,15 +70,15 @@ public static int Execute(this IDbConnection cnn, string sql, object param = nul
Example usage:
```
csharp
connection
.
Execute
(
@"
var
count
=
connection
.
Execute
(
@"
set nocount on
create table #t(i int)
set nocount off
insert #t
select @a a union all select @b
set nocount on
drop table #t"
,
new
{
a
=
1
,
b
=
2
})
.
IsEqualTo
(
2
);
drop table #t"
,
new
{
a
=
1
,
b
=
2
})
;
Assert
.
Equal
(
2
,
count
);
```
Execute a Command multiple times
...
...
@@ -101,9 +89,10 @@ The same signature also allows you to conveniently and efficiently execute a com
Example usage:
```
csharp
connection
.
Execute
(
@"insert MyTable(colA, colB) values (@a, @b)"
,
var
count
=
connection
.
Execute
(
@"insert MyTable(colA, colB) values (@a, @b)"
,
new
[]
{
new
{
a
=
1
,
b
=
1
},
new
{
a
=
2
,
b
=
2
},
new
{
a
=
3
,
b
=
3
}
}
).
IsEqualTo
(
3
);
// 3 rows inserted: "1,1", "2,2" and "3,3"
);
Assert
.
Equal
(
3
,
count
);
// 3 rows inserted: "1,1", "2,2" and "3,3"
```
This works for any parameter that implements IEnumerable
<T>
for some T.
...
...
@@ -240,10 +229,10 @@ Order by p.Id";
var
data
=
connection
.
Query
<
Post
,
User
,
Post
>(
sql
,
(
post
,
user
)
=>
{
post
.
Owner
=
user
;
return
post
;});
var
post
=
data
.
First
();
post
.
Content
.
IsEqualTo
(
"Sams Post1"
);
post
.
Id
.
IsEqualTo
(
1
);
post
.
Owner
.
Name
.
IsEqualTo
(
"Sam"
);
post
.
Owner
.
Id
.
IsEqualTo
(
99
);
Assert
.
Equal
(
"Sams Post1"
,
post
.
Content
);
Assert
.
Equal
(
1
,
post
.
Id
);
Assert
.
Equal
(
"Sam"
,
post
.
Owner
.
Name
);
Assert
.
Equal
(
99
,
post
.
Owner
.
Id
);
```
Dapper is able to split the returned row by making an assumption that your Id columns are named
`Id`
or
`id`
. If your primary key is different or you would like to split the row at a point other than
`Id`
, use the optional
`splitOn`
parameter.
...
...
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