Commit 61998c4f authored by johandanforth's avatar johandanforth

bug in keypropertiescache

parent 7f22bff5
......@@ -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");
}
......
......@@ -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");
}
......
......@@ -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");
}
......
......@@ -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())
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment