public async Task DeleteCustomer(ShardKey customerKey, CancellationToken cancellation) { customerKey.ThrowIfInvalidOrigin(DataOrigins.Customer); var customerPrms = new ParameterCollection() .AddPgIntegerInputParameter("customerid", customerKey.RecordId) .AddPgSmallintInputParameter("customershardid", customerKey.ShardId); var shards = await _shardSet[customerKey].Write.ListAsync <short>(Queries.CustomerDelete, customerPrms, "contactshardid", cancellation); if (shards.Count > 0) { var foreignShards = new ShardsValues <short>(); foreach (var shd in shards) { foreignShards.Add(shd); } await _shardSet.Write.RunAsync(Queries.ContactCustomersDelete, customerPrms, foreignShards, cancellation); } }
public async Task DeleteCustomer(ShardKey customerKey, CancellationToken cancellation) { customerKey.ThrowIfInvalidOrigin(DataOrigins.Customer); var customerPrms = new ParameterCollection() .AddSqlIntInputParameter("@CustomerId", customerKey.RecordId) .AddSqlTinyIntInputParameter("@CustomerShardId", customerKey.ShardId); await _shardSet.Write.RunAsync(Queries.CustomerDelete, customerPrms, cancellation); //Deleting on all shards, as their may be foreign Contact references to this Customer var shards = await _shardSet[customerKey].Write.ListAsync <byte>(Queries.CustomerDelete, customerPrms, "contactshardid", cancellation); if (shards.Count > 0) { var foreignShards = new ShardsValues <byte>(); foreach (var shd in shards) { foreignShards.Add(shd); } await _shardSet.Write.RunAsync(Queries.ContactCustomersDelete, customerPrms, foreignShards, cancellation); } }