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

Fixed #530 using technique that fixed #418 for async code. #533

Closed
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions Dapper.Contrib/SqlMapperExtensions.Async.cs
Expand Up @@ -203,7 +203,7 @@ public static partial class SqlMapperExtensions
type = type.GetGenericArguments()[0];
}

var keyProperties = KeyPropertiesCache(type);
var keyProperties = KeyPropertiesCache(type).ToList(); //added ToList() due to issue #418/#530, must work on a list copy
var explicitKeyProperties = ExplicitKeyPropertiesCache(type);
if (!keyProperties.Any() && !explicitKeyProperties.Any())
throw new ArgumentException("Entity must have at least one [Key] or [ExplicitKey] property");
Expand Down Expand Up @@ -264,7 +264,7 @@ public static partial class SqlMapperExtensions
type = type.GetGenericArguments()[0];
}

var keyProperties = KeyPropertiesCache(type);
var keyProperties = KeyPropertiesCache(type).ToList(); //added ToList() due to issue #418/#530, must work on a list copy
var explicitKeyProperties = ExplicitKeyPropertiesCache(type);
if (!keyProperties.Any() && !explicitKeyProperties.Any())
throw new ArgumentException("Entity must have at least one [Key] or [ExplicitKey] property");
Expand Down
29 changes: 29 additions & 0 deletions Dapper.Tests.Contrib/TestSuite.Async.cs
Expand Up @@ -15,6 +15,35 @@ namespace Dapper.Tests.Contrib
{
public abstract partial class TestSuite
{
[Fact]
public async Task Issue530()
{
using (var connection = GetOpenConnection())
{
//update first (will fail) then insert
//added for bug #418/#530
var updateObject = new ObjectX
{
ObjectXId = Guid.NewGuid().ToString(),
Name = "Someone"
};
var updates = await connection.UpdateAsync(updateObject);
updates.IsFalse();

await connection.DeleteAllAsync<ObjectX>();

var objectXId = Guid.NewGuid().ToString();
var insertObject = new ObjectX
{
ObjectXId = objectXId,
Name = "Someone else"
};
await connection.InsertAsync(insertObject);
var list = await connection.GetAllAsync<ObjectX>();
list.Count().IsEqualTo(1);
}
}

/// <summary>
/// Tests for issue #351
/// </summary>
Expand Down