Commit 61707905 authored by james-hester-ah's avatar james-hester-ah Committed by Nick Craver

Fix issue #418 for DeleteAsync (#1309)

Fix issue #418 for DeleteAsync (with tests)
parent 9282ef28
......@@ -307,18 +307,18 @@ public static partial class SqlMapperExtensions
throw new ArgumentException("Entity must have at least one [Key] or [ExplicitKey] property");
var name = GetTableName(type);
keyProperties.AddRange(explicitKeyProperties);
var allKeyProperties = keyProperties.Concat(explicitKeyProperties).ToList();
var sb = new StringBuilder();
sb.AppendFormat("DELETE FROM {0} WHERE ", name);
var adapter = GetFormatter(connection);
for (var i = 0; i < keyProperties.Count; i++)
for (var i = 0; i < allKeyProperties.Count; i++)
{
var property = keyProperties[i];
var property = allKeyProperties[i];
adapter.AppendColumnNameEqualsValue(sb, property.Name);
if (i < keyProperties.Count - 1)
if (i < allKeyProperties.Count - 1)
sb.Append(" AND ");
}
var deleted = await connection.ExecuteAsync(sb.ToString(), entityToDelete, transaction, commandTimeout).ConfigureAwait(false);
......
......@@ -83,6 +83,17 @@ public async Task TypeWithGenericParameterCanBeDeletedAsync()
}
}
[Fact]
public async Task GetAsyncSucceedsAfterDeleteAsyncWhenExplicitKeyPresent()
{
using (var connection = GetOpenConnection())
{
await connection.DeleteAsync(new ObjectX { ObjectXId = Guid.NewGuid().ToString() }).ConfigureAwait(false);
var retrieved = await connection.GetAsync<ObjectX>(Guid.NewGuid().ToString()).ConfigureAwait(false);
Assert.Null(retrieved);
}
}
/// <summary>
/// Tests for issue #351
/// </summary>
......
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