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
61998c4f
Commit
61998c4f
authored
Oct 27, 2015
by
johandanforth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug in keypropertiescache
parent
7f22bff5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
2 deletions
+39
-2
Program.cs
Dapper.Contrib.MsSqlTests NET45/Program.cs
+2
-0
Program.cs
Dapper.Contrib.SqliteTests NET45/Program.cs
+1
-0
Program.cs
Dapper.Contrib.Tests NET45/Program.cs
+1
-0
Tests.cs
Dapper.Contrib.Tests/Tests.cs
+30
-0
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+5
-2
No files found.
Dapper.Contrib.MsSqlTests NET45/Program.cs
View file @
61998c4f
...
...
@@ -52,6 +52,7 @@ private static void DropTables()
connection
.
Execute
(
@" drop table Results "
);
connection
.
Execute
(
@" drop table ObjectX "
);
connection
.
Execute
(
@" drop table ObjectY "
);
connection
.
Execute
(
@" drop table ObjectZ "
);
}
Console
.
WriteLine
(
"Created database"
);
}
...
...
@@ -69,6 +70,7 @@ private static void SetupTables()
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"
);
}
...
...
Dapper.Contrib.SqliteTests NET45/Program.cs
View file @
61998c4f
...
...
@@ -38,6 +38,7 @@ private static void Setup()
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) "
);
}
Console
.
WriteLine
(
"Created database"
);
}
...
...
Dapper.Contrib.Tests NET45/Program.cs
View file @
61998c4f
...
...
@@ -38,6 +38,7 @@ private static void Setup()
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"
);
}
...
...
Dapper.Contrib.Tests/Tests.cs
View file @
61998c4f
...
...
@@ -31,6 +31,14 @@ public class ObjectY
public
int
ObjectYId
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
[
Table
(
"ObjectZ"
)]
public
class
ObjectZ
{
[
ExplicitKey
]
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
public
interface
IUser
{
...
...
@@ -153,6 +161,28 @@ public void InsertGetUpdateDeleteWithExplicitKey()
}
}
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();
}
}
public
void
ShortIdentity
()
{
using
(
var
connection
=
GetOpenConnection
())
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
61998c4f
...
...
@@ -84,12 +84,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
);
}
...
...
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