Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dapper.Contrib alter caching keys issue #703 #704

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dapper.Contrib/SqlMapperExtensions.cs
Expand Up @@ -86,7 +86,7 @@ private static List<PropertyInfo> ComputedPropertiesCache(Type type)
var computedProperties = TypePropertiesCache(type).Where(p => p.GetCustomAttributes(true).Any(a => a is ComputedAttribute)).ToList();

ComputedProperties[type.TypeHandle] = computedProperties;
return computedProperties;
return computedProperties.ToList();
}

private static List<PropertyInfo> ExplicitKeyPropertiesCache(Type type)
Expand All @@ -99,7 +99,7 @@ private static List<PropertyInfo> ExplicitKeyPropertiesCache(Type type)
var explicitKeyProperties = TypePropertiesCache(type).Where(p => p.GetCustomAttributes(true).Any(a => a is ExplicitKeyAttribute)).ToList();

ExplicitKeyProperties[type.TypeHandle] = explicitKeyProperties;
return explicitKeyProperties;
return explicitKeyProperties.ToList();
}

private static List<PropertyInfo> KeyPropertiesCache(Type type)
Expand All @@ -122,7 +122,7 @@ private static List<PropertyInfo> KeyPropertiesCache(Type type)
}

KeyProperties[type.TypeHandle] = keyProperties;
return keyProperties;
return keyProperties.ToList();
}

private static List<PropertyInfo> TypePropertiesCache(Type type)
Expand Down
29 changes: 29 additions & 0 deletions Dapper.Tests.Contrib/TestSuite.Async.cs
Expand Up @@ -9,8 +9,37 @@

namespace Dapper.Tests.Contrib
{
[Table("ObjectW")]
public class ObjectW
{
[ExplicitKey]
public Guid ObjectWId { get; set; }
public string Name { get; set; }
}

public abstract partial class TestSuite
{
[Fact]
public async Task Issue703()
{
using (var connection = GetOpenConnection())
{
//update first (will fail) then insert
//added for bug #418/#703
var objectW = new ObjectW
{
ObjectWId = Guid.NewGuid(),
Name = "Someone"
};
var updates = await connection.UpdateAsync(objectW);
Assert.False(updates);

await connection.InsertAsync(objectW);
var list = await connection.GetAllAsync<ObjectW>();
Assert.Single(list);
}
}

[Fact]
public async Task TypeWithGenericParameterCanBeInsertedAsync()
{
Expand Down
6 changes: 6 additions & 0 deletions Dapper.Tests.Contrib/TestSuites.cs
Expand Up @@ -49,6 +49,8 @@ static SqlServerTestSuite()
connection.Execute("CREATE TABLE Automobiles (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null);");
dropTable("Results");
connection.Execute("CREATE TABLE Results (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, [Order] int not null);");
dropTable("ObjectW");
connection.Execute("CREATE TABLE ObjectW (ObjectWId uniqueidentifier not null, Name nvarchar(100) not null);");
dropTable("ObjectX");
connection.Execute("CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);");
dropTable("ObjectY");
Expand Down Expand Up @@ -100,6 +102,8 @@ static MySqlServerTestSuite()
connection.Execute("CREATE TABLE Automobiles (Id int not null AUTO_INCREMENT PRIMARY KEY, Name nvarchar(100) not null);");
dropTable("Results");
connection.Execute("CREATE TABLE Results (Id int not null AUTO_INCREMENT PRIMARY KEY, Name nvarchar(100) not null, `Order` int not null);");
dropTable("ObjectW");
connection.Execute("CREATE TABLE ObjectW (ObjectWId CHAR(38) not null, Name nvarchar(100) not null);");
dropTable("ObjectX");
connection.Execute("CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);");
dropTable("ObjectY");
Expand Down Expand Up @@ -142,6 +146,7 @@ static SQLiteTestSuite()
connection.Execute("CREATE TABLE Users (Id integer primary key autoincrement not null, Name nvarchar(100) not null, Age int not null) ");
connection.Execute("CREATE TABLE Automobiles (Id integer primary key autoincrement not null, Name nvarchar(100) not null) ");
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 ObjectW (ObjectWId CHAR(38) not null, Name nvarchar(100) 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) ");
Expand Down Expand Up @@ -174,6 +179,7 @@ static SqlCETestSuite()
connection.Execute(@"CREATE TABLE Users (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, Age int not null) ");
connection.Execute(@"CREATE TABLE Automobiles (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null) ");
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 ObjectW (ObjectWId uniqueidentifier not null, Name nvarchar(100) 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) ");
Expand Down