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
e24c472f
Commit
e24c472f
authored
Nov 26, 2015
by
Nick Craver
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'johandanforth-bug-in-keypropertiescache'
parents
07572a22
eb51910c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
4 deletions
+43
-4
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+5
-2
TestSuite.cs
Dapper.Tests.Contrib/TestSuite.cs
+32
-2
TestSuites.cs
Dapper.Tests.Contrib/TestSuites.cs
+6
-0
No files found.
Dapper.Contrib/SqlMapperExtensions.cs
View file @
e24c472f
...
...
@@ -91,12 +91,15 @@ private static List<PropertyInfo> KeyPropertiesCache(Type type)
}
var
allProperties
=
TypePropertiesCache
(
type
);
var
keyProperties
=
allProperties
.
Where
(
p
=>
p
.
GetCustomAttributes
(
true
).
Any
(
a
=>
a
is
KeyAttribute
)).
ToList
();
var
keyProperties
=
allProperties
.
Where
(
p
=>
{
return
p
.
GetCustomAttributes
(
true
).
Any
(
a
=>
a
is
KeyAttribute
);
}).
ToList
();
if
(
keyProperties
.
Count
==
0
)
{
var
idProp
=
allProperties
.
FirstOrDefault
(
p
=>
p
.
Name
.
ToLower
()
==
"id"
);
if
(
idProp
!=
null
)
if
(
idProp
!=
null
&&
!
idProp
.
GetCustomAttributes
(
true
).
Any
(
a
=>
a
is
ExplicitKeyAttribute
)
)
{
keyProperties
.
Add
(
idProp
);
}
...
...
Dapper.Tests.Contrib/TestSuite.cs
View file @
e24c472f
...
...
@@ -35,6 +35,14 @@ public class ObjectY
public
string
Name
{
get
;
set
;
}
}
[
Table
(
"ObjectZ"
)]
public
class
ObjectZ
{
[
ExplicitKey
]
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
public
interface
IUser
{
[
Key
]
...
...
@@ -149,6 +157,28 @@ public void GetAllWithExplicitKey()
}
}
[
Fact
]
public
void
InsertGetUpdateDeleteWithExplicitKeyNamedId
()
{
using
(
var
connection
=
GetOpenConnection
())
{
const
int
id
=
42
;
var
o2
=
new
ObjectZ
{
Id
=
id
,
Name
=
"Foo"
};
connection
.
Insert
(
o2
);
var
list2
=
connection
.
Query
<
ObjectZ
>(
"select * from ObjectZ"
).
ToList
();
list2
.
Count
.
IsEqualTo
(
1
);
o2
=
connection
.
Get
<
ObjectZ
>(
id
);
o2
.
Id
.
IsEqualTo
(
id
);
//o2.Name = "Bar";
//connection.Update(o2);
//o2 = connection.Get<ObjectY>(id);
//o2.Name.IsEqualTo("Bar");
//connection.Delete(o2);
//o2 = connection.Get<ObjectY>(id);
//o2.IsNull();
}
}
[
Fact
]
public
void
ShortIdentity
()
{
...
...
Dapper.Tests.Contrib/TestSuites.cs
View file @
e24c472f
...
...
@@ -55,6 +55,8 @@ static SqlServerTestSuite()
connection
.
Execute
(
@"CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);"
);
dropTable
(
"ObjectY"
);
connection
.
Execute
(
@"CREATE TABLE ObjectY (ObjectYId int not null, Name nvarchar(100) not null);"
);
dropTable
(
"ObjectZ"
);
connection
.
Execute
(
@"CREATE TABLE ObjectZ (Id int not null, Name nvarchar(100) not null);"
);
}
}
}
...
...
@@ -101,6 +103,8 @@ static MySqlServerTestSuite()
connection
.
Execute
(
@"CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);"
);
dropTable
(
"ObjectY"
);
connection
.
Execute
(
@"CREATE TABLE ObjectY (ObjectYId int not null, Name nvarchar(100) not null);"
);
dropTable
(
"ObjectZ"
);
connection
.
Execute
(
@"CREATE TABLE ObjectZ (Id int not null, Name nvarchar(100) not null);"
);
}
}
catch
(
MySqlException
e
)
...
...
@@ -141,6 +145,7 @@ static SQLiteTestSuite()
connection
.
Execute
(
@"CREATE TABLE Results (Id integer primary key autoincrement not null, Name nvarchar(100) not null, [Order] int not null) "
);
connection
.
Execute
(
@"CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null) "
);
connection
.
Execute
(
@"CREATE TABLE ObjectY (ObjectYId integer not null, Name nvarchar(100) not null) "
);
connection
.
Execute
(
@"CREATE TABLE ObjectZ (Id integer not null, Name nvarchar(100) not null) "
);
}
}
}
...
...
@@ -171,6 +176,7 @@ static SqlCETestSuite()
connection
.
Execute
(
@"CREATE TABLE Results (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, [Order] int not null) "
);
connection
.
Execute
(
@"CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null) "
);
connection
.
Execute
(
@"CREATE TABLE ObjectY (ObjectYId int not null, Name nvarchar(100) not null) "
);
connection
.
Execute
(
@"CREATE TABLE ObjectZ (Id int not null, Name nvarchar(100) not null) "
);
}
Console
.
WriteLine
(
"Created database"
);
}
...
...
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