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
27abc447
Commit
27abc447
authored
Apr 23, 2015
by
johan_danforth@hotmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spring cleaning in Contrib areas, more share of code between framework versions in Contrib
parent
bce293a5
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
518 additions
and
1362 deletions
+518
-1362
Dapper.Contrib NET45.csproj
Dapper.Contrib NET45/Dapper.Contrib NET45.csproj
+4
-1
SqlMapperExtensions.cs
Dapper.Contrib NET45/SqlMapperExtensions.cs
+0
-853
SqlMapperExtensionsAsync.cs
Dapper.Contrib NET45/SqlMapperExtensionsAsync.cs
+300
-0
Assert.cs
Dapper.Contrib.Tests NET45/Assert.cs
+0
-53
Dapper.Contrib.Tests NET45.csproj
Dapper.Contrib.Tests NET45/Dapper.Contrib.Tests NET45.csproj
+7
-3
Program.cs
Dapper.Contrib.Tests NET45/Program.cs
+10
-43
Tests.cs
Dapper.Contrib.Tests NET45/Tests.cs
+0
-198
TestsAsync.cs
Dapper.Contrib.Tests NET45/TestsAsync.cs
+2
-3
Dapper.Contrib.Tests.csproj
Dapper.Contrib.Tests/Dapper.Contrib.Tests.csproj
+1
-4
Program.cs
Dapper.Contrib.Tests/Program.cs
+0
-4
Tests.cs
Dapper.Contrib.Tests/Tests.cs
+11
-7
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+183
-193
No files found.
Dapper.Contrib NET45/Dapper.Contrib NET45.csproj
View file @
27abc447
...
@@ -44,7 +44,10 @@
...
@@ -44,7 +44,10 @@
<Compile
Include=
"..\Dapper.Contrib\Properties\AssemblyInfo.cs"
>
<Compile
Include=
"..\Dapper.Contrib\Properties\AssemblyInfo.cs"
>
<Link>
AssemblyInfo.cs
</Link>
<Link>
AssemblyInfo.cs
</Link>
</Compile>
</Compile>
<Compile
Include=
"SqlMapperExtensions.cs"
/>
<Compile
Include=
"..\Dapper.Contrib\SqlMapperExtensions.cs"
>
<Link>
SqlMapperExtensions.cs
</Link>
</Compile>
<Compile
Include=
"SqlMapperExtensionsAsync.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Folder
Include=
"Properties\"
/>
<Folder
Include=
"Properties\"
/>
...
...
Dapper.Contrib NET45/SqlMapperExtensions.cs
deleted
100644 → 0
View file @
bce293a5
This diff is collapsed.
Click to expand it.
Dapper.Contrib NET45/SqlMapperExtensionsAsync.cs
0 → 100644
View file @
27abc447
This diff is collapsed.
Click to expand it.
Dapper.Contrib.Tests NET45/Assert.cs
deleted
100644 → 0
View file @
bce293a5
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
namespace
Dapper.Contrib.Tests_NET45
{
/// <summary>
/// Assert extensions borrowed from Sam's code in DapperTests
/// </summary>
static
class
Assert
{
public
static
void
IsEqualTo
<
T
>(
this
T
obj
,
T
other
)
{
if
(!
obj
.
Equals
(
other
))
{
throw
new
ApplicationException
(
string
.
Format
(
"{0} should be equals to {1}"
,
obj
,
other
));
}
}
public
static
void
IsSequenceEqualTo
<
T
>(
this
IEnumerable
<
T
>
obj
,
IEnumerable
<
T
>
other
)
{
if
(!
obj
.
SequenceEqual
(
other
))
{
throw
new
ApplicationException
(
string
.
Format
(
"{0} should be equals to {1}"
,
obj
,
other
));
}
}
public
static
void
IsFalse
(
this
bool
b
)
{
if
(
b
)
{
throw
new
ApplicationException
(
"Expected false"
);
}
}
public
static
void
IsTrue
(
this
bool
b
)
{
if
(!
b
)
{
throw
new
ApplicationException
(
"Expected true"
);
}
}
public
static
void
IsNull
(
this
object
obj
)
{
if
(
obj
!=
null
)
{
throw
new
ApplicationException
(
"Expected null"
);
}
}
}
}
\ No newline at end of file
Dapper.Contrib.Tests NET45/Dapper.Contrib.Tests NET45.csproj
View file @
27abc447
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<ProjectGuid>
{7A85178F-4ADC-4E4C-BF08-17FC99488A9A}
</ProjectGuid>
<ProjectGuid>
{7A85178F-4ADC-4E4C-BF08-17FC99488A9A}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
Dapper.Contrib.Tests
_NET45
</RootNamespace>
<RootNamespace>
Dapper.Contrib.Tests
</RootNamespace>
<AssemblyName>
Dapper.Contrib.Tests NET45
</AssemblyName>
<AssemblyName>
Dapper.Contrib.Tests NET45
</AssemblyName>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<FileAlignment>
512
</FileAlignment>
...
@@ -42,10 +42,14 @@
...
@@ -42,10 +42,14 @@
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"Assert.cs"
/>
<Compile
Include=
"..\Dapper.Contrib.Tests\Assert.cs"
>
<Link>
Assert.cs
</Link>
</Compile>
<Compile
Include=
"..\Dapper.Contrib.Tests\Tests.cs"
>
<Link>
Tests.cs
</Link>
</Compile>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Tests.cs"
/>
<Compile
Include=
"TestsAsync.cs"
/>
<Compile
Include=
"TestsAsync.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
Dapper.Contrib.Tests NET45/Program.cs
View file @
27abc447
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Data.SqlServerCe
;
using
System.Data.SqlServerCe
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
namespace
Dapper.Contrib.Tests
_NET45
namespace
Dapper.Contrib.Tests
{
{
class
Program
class
Program
{
{
...
@@ -47,50 +43,21 @@ private static void RunTests()
...
@@ -47,50 +43,21 @@ private static void RunTests()
var
tester
=
new
Tests
();
var
tester
=
new
Tests
();
foreach
(
var
method
in
typeof
(
Tests
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
DeclaredOnly
))
foreach
(
var
method
in
typeof
(
Tests
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
DeclaredOnly
))
{
{
if
(
method
.
ReturnType
!=
typeof
(
Task
))
Console
.
Write
(
"Running "
+
method
.
Name
);
{
method
.
Invoke
(
tester
,
null
);
Console
.
Write
(
"Running "
+
method
.
Name
);
Console
.
WriteLine
(
" - OK!"
);
method
.
Invoke
(
tester
,
null
);
Console
.
WriteLine
(
" - OK!"
);
}
}
}
}
}
private
static
void
RunAsyncTests
()
private
static
void
RunAsyncTests
()
{
{
var
tester
=
new
TestsAsync
();
var
tester
=
new
TestsAsync
();
foreach
(
var
method
in
typeof
(
TestsAsync
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
DeclaredOnly
))
Console
.
Write
(
"Running TableNameAsync"
);
{
Task
.
WaitAll
(
tester
.
TableNameAsync
());
Console
.
Write
(
"Running "
+
method
.
Name
);
Console
.
WriteLine
(
" - OK!"
);
Task
.
WaitAll
((
Task
)
method
.
Invoke
(
tester
,
null
));
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running TestSimpleGetAsync"
);
}
Task
.
WaitAll
(
tester
.
TestSimpleGetAsync
());
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running InsertGetUpdateAsync"
);
Task
.
WaitAll
(
tester
.
InsertGetUpdateAsync
());
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running InsertCheckKeyAsync"
);
Task
.
WaitAll
(
tester
.
InsertCheckKeyAsync
());
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running BuilderSelectClauseAsync"
);
Task
.
WaitAll
(
tester
.
BuilderSelectClauseAsync
());
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running BuilderTemplateWOCompositionAsync"
);
Task
.
WaitAll
(
tester
.
BuilderTemplateWOCompositionAsync
());
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running InsertFieldWithReservedNameAsync"
);
Task
.
WaitAll
(
tester
.
InsertFieldWithReservedNameAsync
());
Console
.
WriteLine
(
" - OK!"
);
Console
.
Write
(
"Running DeleteAllAsync"
);
Task
.
WaitAll
(
tester
.
DeleteAllAsync
());
Console
.
WriteLine
(
" - OK!"
);
}
}
}
}
}
}
Dapper.Contrib.Tests NET45/Tests.cs
deleted
100644 → 0
View file @
bce293a5
using
System.Data
;
using
System.Data.SqlServerCe
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
Dapper.Contrib.Extensions
;
using
System.Collections.Generic
;
using
System
;
using
Dapper
;
namespace
Dapper.Contrib.Tests_NET45
{
public
interface
IUser
{
[
Key
]
int
Id
{
get
;
set
;
}
string
Name
{
get
;
set
;
}
int
Age
{
get
;
set
;
}
}
public
class
User
:
IUser
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
int
Age
{
get
;
set
;
}
}
[
Table
(
"Automobiles"
)]
public
class
Car
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
[
Table
(
"Results"
)]
public
class
Result
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
int
Order
{
get
;
set
;
}
}
public
class
Tests
{
private
IDbConnection
GetOpenConnection
()
{
var
projLoc
=
Assembly
.
GetAssembly
(
GetType
()).
Location
;
var
projFolder
=
Path
.
GetDirectoryName
(
projLoc
);
var
connection
=
new
SqlCeConnection
(
"Data Source = "
+
projFolder
+
"\\Test.sdf;"
);
connection
.
Open
();
return
connection
;
}
public
void
TableName
()
{
using
(
var
connection
=
GetOpenConnection
())
{
// tests against "Automobiles" table (Table attribute)
connection
.
Insert
(
new
Car
{
Name
=
"Volvo"
});
connection
.
Get
<
Car
>(
1
).
Name
.
IsEqualTo
(
"Volvo"
);
connection
.
Update
(
new
Car
()
{
Id
=
1
,
Name
=
"Saab"
}).
IsEqualTo
(
true
);
connection
.
Get
<
Car
>(
1
).
Name
.
IsEqualTo
(
"Saab"
);
connection
.
Delete
(
new
Car
()
{
Id
=
1
}).
IsEqualTo
(
true
);
connection
.
Get
<
Car
>(
1
).
IsNull
();
}
}
public
void
TestSimpleGet
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
id
=
connection
.
Insert
(
new
User
{
Name
=
"Adama"
,
Age
=
10
});
var
user
=
connection
.
Get
<
User
>(
id
);
user
.
Id
.
IsEqualTo
((
int
)
id
);
user
.
Name
.
IsEqualTo
(
"Adama"
);
connection
.
Delete
(
user
);
}
}
public
void
InsertGetUpdate
()
{
using
(
var
connection
=
GetOpenConnection
())
{
connection
.
Get
<
User
>(
3
).
IsNull
();
var
id
=
connection
.
Insert
(
new
User
{
Name
=
"Adam"
,
Age
=
10
});
//get a user with "isdirty" tracking
var
user
=
connection
.
Get
<
IUser
>(
id
);
user
.
Name
.
IsEqualTo
(
"Adam"
);
connection
.
Update
(
user
).
IsEqualTo
(
false
);
//returns false if not updated, based on tracking
user
.
Name
=
"Bob"
;
connection
.
Update
(
user
).
IsEqualTo
(
true
);
//returns true if updated, based on tracking
user
=
connection
.
Get
<
IUser
>(
id
);
user
.
Name
.
IsEqualTo
(
"Bob"
);
//get a user with no tracking
var
notrackedUser
=
connection
.
Get
<
User
>(
id
);
notrackedUser
.
Name
.
IsEqualTo
(
"Bob"
);
connection
.
Update
(
notrackedUser
).
IsEqualTo
(
true
);
//returns true, even though user was not changed
notrackedUser
.
Name
=
"Cecil"
;
connection
.
Update
(
notrackedUser
).
IsEqualTo
(
true
);
connection
.
Get
<
User
>(
id
).
Name
.
IsEqualTo
(
"Cecil"
);
connection
.
Query
<
User
>(
"select * from Users"
).
Count
().
IsEqualTo
(
1
);
connection
.
Delete
(
user
).
IsEqualTo
(
true
);
connection
.
Query
<
User
>(
"select * from Users"
).
Count
().
IsEqualTo
(
0
);
connection
.
Update
(
notrackedUser
).
IsEqualTo
(
false
);
//returns false, user not found
}
}
public
void
InsertCheckKey
()
{
using
(
var
connection
=
GetOpenConnection
())
{
connection
.
Get
<
IUser
>(
3
).
IsNull
();
User
user
=
new
User
{
Name
=
"Adamb"
,
Age
=
10
};
int
id
=
(
int
)
connection
.
Insert
(
user
);
user
.
Id
.
IsEqualTo
(
id
);
}
}
public
void
BuilderSelectClause
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
rand
=
new
Random
(
8675309
);
var
data
=
new
List
<
User
>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
var
nU
=
new
User
{
Age
=
rand
.
Next
(
70
),
Id
=
i
,
Name
=
Guid
.
NewGuid
().
ToString
()
};
data
.
Add
(
nU
);
nU
.
Id
=
(
int
)
connection
.
Insert
<
User
>(
nU
);
}
var
builder
=
new
SqlBuilder
();
var
justId
=
builder
.
AddTemplate
(
"SELECT /**select**/ FROM Users"
);
var
all
=
builder
.
AddTemplate
(
"SELECT Name, /**select**/, Age FROM Users"
);
builder
.
Select
(
"Id"
);
var
ids
=
connection
.
Query
<
int
>(
justId
.
RawSql
,
justId
.
Parameters
);
var
users
=
connection
.
Query
<
User
>(
all
.
RawSql
,
all
.
Parameters
);
foreach
(
var
u
in
data
)
{
if
(!
ids
.
Any
(
i
=>
u
.
Id
==
i
))
throw
new
Exception
(
"Missing ids in select"
);
if
(!
users
.
Any
(
a
=>
a
.
Id
==
u
.
Id
&&
a
.
Name
==
u
.
Name
&&
a
.
Age
==
u
.
Age
))
throw
new
Exception
(
"Missing users in select"
);
}
}
}
public
void
BuilderTemplateWOComposition
()
{
var
builder
=
new
SqlBuilder
();
var
template
=
builder
.
AddTemplate
(
"SELECT COUNT(*) FROM Users WHERE Age = @age"
,
new
{
age
=
5
});
if
(
template
.
RawSql
==
null
)
throw
new
Exception
(
"RawSql null"
);
if
(
template
.
Parameters
==
null
)
throw
new
Exception
(
"Parameters null"
);
using
(
var
connection
=
GetOpenConnection
())
{
connection
.
Insert
(
new
User
{
Age
=
5
,
Name
=
"Testy McTestington"
});
if
(
connection
.
Query
<
int
>(
template
.
RawSql
,
template
.
Parameters
).
Single
()
!=
1
)
throw
new
Exception
(
"Query failed"
);
}
}
public
void
InsertFieldWithReservedName
()
{
using
(
var
conneciton
=
GetOpenConnection
())
{
var
id
=
conneciton
.
Insert
(
new
Result
()
{
Name
=
"Adam"
,
Order
=
1
});
var
result
=
conneciton
.
Get
<
Result
>(
id
);
result
.
Order
.
IsEqualTo
(
1
);
}
}
public
void
DeleteAll
()
{
using
(
var
connection
=
GetOpenConnection
())
{
var
id1
=
connection
.
Insert
(
new
User
()
{
Name
=
"Alice"
,
Age
=
32
});
var
id2
=
connection
.
Insert
(
new
User
()
{
Name
=
"Bob"
,
Age
=
33
});
connection
.
DeleteAll
<
User
>();
connection
.
Get
<
User
>(
id1
).
IsNull
();
connection
.
Get
<
User
>(
id2
).
IsNull
();
}
}
}
}
Dapper.Contrib.Tests NET45/TestsAsync.cs
View file @
27abc447
...
@@ -3,14 +3,13 @@
...
@@ -3,14 +3,13 @@
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
Dapper.Contrib.Extensions
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System
;
using
System
;
using
Dapper
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Dapper.Contrib.Extensions
;
namespace
Dapper.Contrib.Tests
_NET45
namespace
Dapper.Contrib.Tests
{
{
public
class
TestsAsync
public
class
TestsAsync
{
{
...
...
Dapper.Contrib.Tests/Dapper.Contrib.Tests.csproj
View file @
27abc447
...
@@ -44,10 +44,7 @@
...
@@ -44,10 +44,7 @@
<ItemGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"
>
<Reference
Include=
"System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"
/>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
Dependencies\System.Data.SqlServerCe.dll
</HintPath>
</Reference>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
...
...
Dapper.Contrib.Tests/Program.cs
View file @
27abc447
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Data.SqlServerCe
;
using
System.Data.SqlServerCe
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Text
;
namespace
Dapper.Contrib.Tests
namespace
Dapper.Contrib.Tests
{
{
...
...
Dapper.Contrib.Tests/Tests.cs
View file @
27abc447
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
using
Dapper.Contrib.Extensions
;
using
Dapper.Contrib.Extensions
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System
;
using
System
;
using
Dapper
;
namespace
Dapper.Contrib.Tests
namespace
Dapper.Contrib.Tests
...
@@ -31,6 +30,8 @@ public class Car
...
@@ -31,6 +30,8 @@ public class Car
{
{
public
int
Id
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
[
Computed
]
public
string
Computed
{
get
;
set
;
}
}
}
[
Table
(
"Results"
)]
[
Table
(
"Results"
)]
...
@@ -58,11 +59,11 @@ public void TableName()
...
@@ -58,11 +59,11 @@ public void TableName()
using
(
var
connection
=
GetOpenConnection
())
using
(
var
connection
=
GetOpenConnection
())
{
{
// tests against "Automobiles" table (Table attribute)
// tests against "Automobiles" table (Table attribute)
connection
.
Insert
(
new
Car
{
Name
=
"Volvo"
}
);
connection
.
Insert
(
new
Car
{
Name
=
"Volvo"
}).
IsEqualTo
(
1
);
connection
.
Get
<
Car
>(
1
).
Name
.
IsEqualTo
(
"Volvo"
);
connection
.
Get
<
Car
>(
1
).
Name
.
IsEqualTo
(
"Volvo"
);
connection
.
Update
(
new
Car
()
{
Id
=
1
,
Name
=
"Saab"
}).
IsEqualTo
(
true
);
connection
.
Update
(
new
Car
()
{
Id
=
1
,
Name
=
"Saab"
}).
IsEqualTo
(
true
);
connection
.
Get
<
Car
>(
1
).
Name
.
IsEqualTo
(
"Saab"
);
connection
.
Get
<
Car
>(
1
).
Name
.
IsEqualTo
(
"Saab"
);
connection
.
Delete
(
new
Car
()
{
Id
=
1
}).
IsEqualTo
(
true
);
connection
.
Delete
(
new
Car
()
{
Id
=
1
}).
IsEqualTo
(
true
);
connection
.
Get
<
Car
>(
1
).
IsNull
();
connection
.
Get
<
Car
>(
1
).
IsNull
();
}
}
}
}
...
@@ -85,8 +86,11 @@ public void InsertGetUpdate()
...
@@ -85,8 +86,11 @@ public void InsertGetUpdate()
{
{
connection
.
Get
<
User
>(
3
).
IsNull
();
connection
.
Get
<
User
>(
3
).
IsNull
();
var
id
=
connection
.
Insert
(
new
User
{
Name
=
"Adam"
,
Age
=
10
});
//insert with computed attribute that should be ignored
connection
.
Insert
(
new
Car
{
Name
=
"Volvo"
,
Computed
=
"this property should be ignored"
});
var
id
=
connection
.
Insert
(
new
User
{
Name
=
"Adam"
,
Age
=
10
});
//get a user with "isdirty" tracking
//get a user with "isdirty" tracking
var
user
=
connection
.
Get
<
IUser
>(
id
);
var
user
=
connection
.
Get
<
IUser
>(
id
);
user
.
Name
.
IsEqualTo
(
"Adam"
);
user
.
Name
.
IsEqualTo
(
"Adam"
);
...
@@ -156,7 +160,7 @@ public void BuilderSelectClause()
...
@@ -156,7 +160,7 @@ public void BuilderSelectClause()
public
void
BuilderTemplateWOComposition
()
public
void
BuilderTemplateWOComposition
()
{
{
var
builder
=
new
SqlBuilder
();
var
builder
=
new
SqlBuilder
();
var
template
=
builder
.
AddTemplate
(
"SELECT COUNT(*) FROM Users WHERE Age = @age"
,
new
{
age
=
5
});
var
template
=
builder
.
AddTemplate
(
"SELECT COUNT(*) FROM Users WHERE Age = @age"
,
new
{
age
=
5
});
if
(
template
.
RawSql
==
null
)
throw
new
Exception
(
"RawSql null"
);
if
(
template
.
RawSql
==
null
)
throw
new
Exception
(
"RawSql null"
);
if
(
template
.
Parameters
==
null
)
throw
new
Exception
(
"Parameters null"
);
if
(
template
.
Parameters
==
null
)
throw
new
Exception
(
"Parameters null"
);
...
@@ -188,7 +192,7 @@ public void DeleteAll()
...
@@ -188,7 +192,7 @@ public void DeleteAll()
{
{
var
id1
=
connection
.
Insert
(
new
User
()
{
Name
=
"Alice"
,
Age
=
32
});
var
id1
=
connection
.
Insert
(
new
User
()
{
Name
=
"Alice"
,
Age
=
32
});
var
id2
=
connection
.
Insert
(
new
User
()
{
Name
=
"Bob"
,
Age
=
33
});
var
id2
=
connection
.
Insert
(
new
User
()
{
Name
=
"Bob"
,
Age
=
33
});
connection
.
DeleteAll
<
User
>();
connection
.
DeleteAll
<
User
>()
.
IsTrue
()
;
connection
.
Get
<
User
>(
id1
).
IsNull
();
connection
.
Get
<
User
>(
id1
).
IsNull
();
connection
.
Get
<
User
>(
id2
).
IsNull
();
connection
.
Get
<
User
>(
id2
).
IsNull
();
}
}
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
27abc447
This diff is collapsed.
Click to expand it.
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