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
86d6454a
Commit
86d6454a
authored
Nov 27, 2012
by
Sam
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #63 from seburgi/master
Added database schema support to Dapper.Rainbow
parents
a91bf721
6ef748ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
Database.cs
Dapper.Rainbow/Database.cs
+22
-3
SqlMapper.cs
Dapper/SqlMapper.cs
+6
-1
No files found.
Dapper.Rainbow/Database.cs
View file @
86d6454a
...
...
@@ -73,7 +73,7 @@ public int Update(TId id, dynamic data)
List
<
string
>
paramNames
=
GetParamNames
((
object
)
data
);
var
builder
=
new
StringBuilder
();
builder
.
Append
(
"update
["
).
Append
(
TableName
).
Append
(
"]
set "
);
builder
.
Append
(
"update
"
).
Append
(
TableName
).
Append
(
"
set "
);
builder
.
AppendLine
(
string
.
Join
(
","
,
paramNames
.
Where
(
n
=>
n
!=
"Id"
).
Select
(
p
=>
p
+
"= @"
+
p
)));
builder
.
Append
(
"where Id = @Id"
);
...
...
@@ -247,7 +247,7 @@ private string DetermineTableName<T>(string likelyTableName)
name
=
likelyTableName
;
if
(!
TableExists
(
name
))
{
name
=
typeof
(
T
).
Name
;
name
=
"["
+
typeof
(
T
).
Name
+
"]"
;
}
tableNameMap
[
typeof
(
T
)]
=
name
;
...
...
@@ -257,7 +257,26 @@ private string DetermineTableName<T>(string likelyTableName)
private
bool
TableExists
(
string
name
)
{
return
connection
.
Query
(
"select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = @name"
,
new
{
name
},
transaction
:
transaction
).
Count
()
==
1
;
string
schemaName
=
null
;
name
=
name
.
Replace
(
"["
,
""
);
name
=
name
.
Replace
(
"]"
,
""
);
if
(
name
.
Contains
(
"."
))
{
var
parts
=
name
.
Split
(
'.'
);
if
(
parts
.
Count
()
==
2
)
{
schemaName
=
parts
[
0
];
name
=
parts
[
1
];
}
}
var
builder
=
new
StringBuilder
(
"select 1 from INFORMATION_SCHEMA.TABLES where "
);
if
(!
String
.
IsNullOrEmpty
(
schemaName
))
builder
.
Append
(
"TABLE_SCHEMA = @schemaName AND "
);
builder
.
Append
(
"TABLE_NAME = @name"
);
return
connection
.
Query
(
builder
.
ToString
(),
new
{
schemaName
,
name
},
transaction
:
transaction
).
Count
()
==
1
;
}
public
int
Execute
(
string
sql
,
dynamic
param
=
null
)
...
...
Dapper/SqlMapper.cs
View file @
86d6454a
...
...
@@ -410,13 +410,18 @@ static SqlMapper()
typeMap
[
typeof
(
Object
)]
=
DbType
.
Object
;
}
public
static
void
AddTypeMap
(
Type
type
,
DbType
dbType
)
{
typeMap
[
type
]
=
dbType
;
}
internal
const
string
LinqBinary
=
"System.Data.Linq.Binary"
;
internal
static
DbType
LookupDbType
(
Type
type
,
string
name
)
{
DbType
dbType
;
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
type
);
if
(
nullUnderlyingType
!=
null
)
type
=
nullUnderlyingType
;
if
(
type
.
IsEnum
)
if
(
type
.
IsEnum
&&
!
typeMap
.
ContainsKey
(
type
)
)
{
type
=
Enum
.
GetUnderlyingType
(
type
);
}
...
...
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