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
dd7bdd3c
Commit
dd7bdd3c
authored
Feb 16, 2012
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Nick happy, better error for constructorless types
parent
edd142d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
SqlMapper.cs
Dapper/SqlMapper.cs
+6
-1
Tests.cs
Tests/Tests.cs
+23
-2
No files found.
Dapper/SqlMapper.cs
View file @
dd7bdd3c
...
@@ -1504,7 +1504,12 @@ static List<FieldInfo> GetSettableFields(Type t)
...
@@ -1504,7 +1504,12 @@ static List<FieldInfo> GetSettableFields(Type t)
}
}
else
else
{
{
il
.
Emit
(
OpCodes
.
Newobj
,
type
.
GetConstructor
(
BindingFlags
.
Instance
|
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
,
null
,
Type
.
EmptyTypes
,
null
));
var
ctor
=
type
.
GetConstructor
(
BindingFlags
.
Instance
|
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
,
null
,
Type
.
EmptyTypes
,
null
);
if
(
ctor
==
null
)
{
throw
new
InvalidOperationException
(
"A parameterless default constructor is required to allow for dapper materialization"
);
}
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
}
}
il
.
BeginExceptionBlock
();
il
.
BeginExceptionBlock
();
...
...
Tests/Tests.cs
View file @
dd7bdd3c
...
@@ -33,6 +33,29 @@ public class ConcreteOrder : Order
...
@@ -33,6 +33,29 @@ public class ConcreteOrder : Order
}
}
}
}
class
NoDefualtConstructor
{
public
NoDefualtConstructor
(
int
a
)
{
A
=
a
;
}
public
int
A
{
get
;
set
;
}
}
public
void
EnsureNoConstructorGivesNiceError
()
{
try
{
connection
.
Query
<
NoDefualtConstructor
>(
"select 1 A"
).
First
();
}
catch
(
InvalidOperationException
e
)
{
e
.
Message
.
IsEqualTo
(
"A parameterless default constructor is required to allow for dapper materialization"
);
}
}
// http://stackoverflow.com/q/8593871
// http://stackoverflow.com/q/8593871
public
void
TestAbstractInheritance
()
public
void
TestAbstractInheritance
()
{
{
...
@@ -42,10 +65,8 @@ public void TestAbstractInheritance()
...
@@ -42,10 +65,8 @@ public void TestAbstractInheritance()
order
.
ProtectedVal
.
IsEqualTo
(
2
);
order
.
ProtectedVal
.
IsEqualTo
(
2
);
order
.
Public
.
IsEqualTo
(
3
);
order
.
Public
.
IsEqualTo
(
3
);
order
.
Concrete
.
IsEqualTo
(
4
);
order
.
Concrete
.
IsEqualTo
(
4
);
}
}
public
void
TestListOfAnsiStrings
()
public
void
TestListOfAnsiStrings
()
{
{
var
results
=
connection
.
Query
<
string
>(
"select * from (select 'a' str union select 'b' union select 'c') X where str in @strings"
,
var
results
=
connection
.
Query
<
string
>(
"select * from (select 'a' str union select 'b' union select 'c') X where str in @strings"
,
...
...
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