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
5f7e88a4
Commit
5f7e88a4
authored
Aug 06, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set InitialLONGFetchSize to -1 if it exists
parent
fa7bfe4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
20 deletions
+41
-20
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+41
-20
No files found.
Dapper NET40/SqlMapper.cs
View file @
5f7e88a4
...
@@ -141,8 +141,8 @@ public struct CommandDefinition
...
@@ -141,8 +141,8 @@ public struct CommandDefinition
internal
IDbCommand
SetupCommand
(
IDbConnection
cnn
,
Action
<
IDbCommand
,
object
>
paramReader
)
internal
IDbCommand
SetupCommand
(
IDbConnection
cnn
,
Action
<
IDbCommand
,
object
>
paramReader
)
{
{
var
cmd
=
cnn
.
CreateCommand
();
var
cmd
=
cnn
.
CreateCommand
();
var
bindByName
=
GetBindByName
(
cmd
.
GetType
());
var
init
=
GetInit
(
cmd
.
GetType
());
if
(
bindByName
!=
null
)
bindByName
(
cmd
,
true
);
if
(
init
!=
null
)
init
(
cmd
);
if
(
transaction
!=
null
)
if
(
transaction
!=
null
)
cmd
.
Transaction
=
transaction
;
cmd
.
Transaction
=
transaction
;
cmd
.
CommandText
=
commandText
;
cmd
.
CommandText
=
commandText
;
...
@@ -157,37 +157,58 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> p
...
@@ -157,37 +157,58 @@ internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> p
return
cmd
;
return
cmd
;
}
}
static
SqlMapper
.
Link
<
Type
,
Action
<
IDbCommand
,
bool
>>
bindByName
Cache
;
static
SqlMapper
.
Link
<
Type
,
Action
<
IDbCommand
>>
commandInit
Cache
;
static
Action
<
IDbCommand
,
bool
>
GetBindByName
(
Type
commandType
)
static
Action
<
IDbCommand
>
GetInit
(
Type
commandType
)
{
{
if
(
commandType
==
null
)
return
null
;
// GIGO
if
(
commandType
==
null
)
return
null
;
// GIGO
Action
<
IDbCommand
,
bool
>
action
;
Action
<
IDbCommand
>
action
;
if
(
SqlMapper
.
Link
<
Type
,
Action
<
IDbCommand
,
bool
>>.
TryGet
(
bindByName
Cache
,
commandType
,
out
action
))
if
(
SqlMapper
.
Link
<
Type
,
Action
<
IDbCommand
>>.
TryGet
(
commandInit
Cache
,
commandType
,
out
action
))
{
{
return
action
;
return
action
;
}
}
var
prop
=
commandType
.
GetProperty
(
"BindByName"
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
);
var
bindByName
=
GetBasicPropertySetter
(
commandType
,
"BindByName"
,
typeof
(
bool
));
var
initialLongFetchSize
=
GetBasicPropertySetter
(
commandType
,
"InitialLONGFetchSize"
,
typeof
(
int
));
action
=
null
;
action
=
null
;
ParameterInfo
[]
indexers
;
if
(
bindByName
!=
null
||
initialLongFetchSize
!=
null
)
MethodInfo
setter
;
if
(
prop
!=
null
&&
prop
.
CanWrite
&&
prop
.
PropertyType
==
typeof
(
bool
)
&&
((
indexers
=
prop
.
GetIndexParameters
())
==
null
||
indexers
.
Length
==
0
)
&&
(
setter
=
prop
.
GetSetMethod
())
!=
null
)
{
{
var
method
=
new
DynamicMethod
(
commandType
.
Name
+
"_
BindByName"
,
null
,
new
Type
[]
{
typeof
(
IDbCommand
),
typeof
(
bool
)
});
var
method
=
new
DynamicMethod
(
commandType
.
Name
+
"_
init"
,
null
,
new
Type
[]
{
typeof
(
IDbCommand
)
});
var
il
=
method
.
GetILGenerator
();
var
il
=
method
.
GetILGenerator
();
il
.
Emit
(
OpCodes
.
Ldarg_0
);
il
.
Emit
(
OpCodes
.
Castclass
,
commandType
);
if
(
bindByName
!=
null
)
il
.
Emit
(
OpCodes
.
Ldarg_1
);
{
il
.
EmitCall
(
OpCodes
.
Callvirt
,
setter
,
null
);
// .BindByName = true
il
.
Emit
(
OpCodes
.
Ldarg_0
);
il
.
Emit
(
OpCodes
.
Castclass
,
commandType
);
il
.
Emit
(
OpCodes
.
Ldc_I4_1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
bindByName
,
null
);
}
if
(
initialLongFetchSize
!=
null
)
{
// .InitialLONGFetchSize = -1
il
.
Emit
(
OpCodes
.
Ldarg_0
);
il
.
Emit
(
OpCodes
.
Castclass
,
commandType
);
il
.
Emit
(
OpCodes
.
Ldc_I4_M1
);
il
.
EmitCall
(
OpCodes
.
Callvirt
,
initialLongFetchSize
,
null
);
}
il
.
Emit
(
OpCodes
.
Ret
);
il
.
Emit
(
OpCodes
.
Ret
);
action
=
(
Action
<
IDbCommand
,
bool
>)
method
.
CreateDelegate
(
typeof
(
Action
<
IDbCommand
,
bool
>));
action
=
(
Action
<
IDbCommand
>)
method
.
CreateDelegate
(
typeof
(
Action
<
IDbCommand
>));
}
}
// cache it
// cache it
SqlMapper
.
Link
<
Type
,
Action
<
IDbCommand
,
bool
>>.
TryAdd
(
ref
bindByName
Cache
,
commandType
,
ref
action
);
SqlMapper
.
Link
<
Type
,
Action
<
IDbCommand
>>.
TryAdd
(
ref
commandInit
Cache
,
commandType
,
ref
action
);
return
action
;
return
action
;
}
}
static
MethodInfo
GetBasicPropertySetter
(
Type
declaringType
,
string
name
,
Type
expectedType
)
{
var
prop
=
declaringType
.
GetProperty
(
name
,
BindingFlags
.
Public
|
BindingFlags
.
Instance
);
ParameterInfo
[]
indexers
;
if
(
prop
!=
null
&&
prop
.
CanWrite
&&
prop
.
PropertyType
==
expectedType
&&
((
indexers
=
prop
.
GetIndexParameters
())
==
null
||
indexers
.
Length
==
0
))
{
return
prop
.
GetSetMethod
();
}
return
null
;
}
}
}
/// <summary>
/// <summary>
...
...
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