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
fd8f3f1d
Commit
fd8f3f1d
authored
Mar 20, 2012
by
jedidja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added INSERT for SQL Compact
parent
4326beac
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
15 deletions
+46
-15
Database.cs
Dapper.Rainbow/Database.cs
+46
-15
No files found.
Dapper.Rainbow/Database.cs
View file @
fd8f3f1d
...
...
@@ -45,6 +45,11 @@ public string TableName
}
}
/// <summary>
/// Insert a row into the db
/// </summary>
/// <param name="data">Either DynamicParameters or an anonymous type or concrete type</param>
/// <returns></returns>
/// <summary>
/// Insert a row into the db
/// </summary>
...
...
@@ -55,12 +60,30 @@ public string TableName
var
o
=
(
object
)
data
;
List
<
string
>
paramNames
=
GetParamNames
(
o
);
if
(
database
.
IsSqlCompact
)
{
paramNames
.
Remove
(
"Id"
);
}
string
cols
=
string
.
Join
(
","
,
paramNames
);
string
cols_params
=
string
.
Join
(
","
,
paramNames
.
Select
(
p
=>
"@"
+
p
));
var
sql
=
"set nocount on insert "
+
TableName
+
" ("
+
cols
+
") values ("
+
cols_params
+
") select cast(scope_identity() as int)"
;
if
(
database
.
IsSqlCompact
)
{
var
sql
=
"insert "
+
TableName
+
" ("
+
cols
+
") values ("
+
cols_params
+
")"
;
if
(
database
.
Execute
(
sql
,
o
)
!=
1
)
{
return
null
;
}
return
(
int
)
database
.
Query
<
decimal
>(
"SELECT @@IDENTITY AS LastInsertedId"
).
Single
();
}
else
{
var
sql
=
"set nocount on insert "
+
TableName
+
" ("
+
cols
+
") values ("
+
cols_params
+
") select cast(scope_identity() as int)"
;
return
database
.
Query
<
int
?>(
sql
,
o
).
Single
();
}
}
/// <summary>
/// Update a record in the DB
...
...
@@ -139,7 +162,6 @@ private static List<string> GetParamNames(object o)
int
commandTimeout
;
DbTransaction
transaction
;
public
static
TDatabase
Init
(
DbConnection
connection
,
int
commandTimeout
)
{
TDatabase
db
=
new
TDatabase
();
...
...
@@ -147,6 +169,13 @@ public static TDatabase Init(DbConnection connection, int commandTimeout)
return
db
;
}
public
static
TDatabase
InitSqlCe
(
DbConnection
connection
)
{
var
db
=
Init
(
connection
,
0
);
db
.
IsSqlCompact
=
true
;
return
db
;
}
private
static
Action
<
Database
<
TDatabase
>>
tableConstructor
;
private
void
InitDatabase
(
DbConnection
connection
,
int
commandTimeout
)
...
...
@@ -161,6 +190,8 @@ private void InitDatabase(DbConnection connection, int commandTimeout)
tableConstructor
(
this
);
}
public
bool
IsSqlCompact
{
get
;
private
set
;
}
public
void
BeginTransaction
(
IsolationLevel
isolation
=
IsolationLevel
.
ReadCommitted
)
{
transaction
=
connection
.
BeginTransaction
(
isolation
);
...
...
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