/// <summary>
 /// Ensures all changes on tenanted entities that are about to be saved to the underlying datastore only reference the currently scoped tenant.
 /// If a tenanted entity has their tenant ID set to that of the 'unset tenant ID' value it will then be set to the ID of the currently scoped tenant.
 /// </summary>
 /// <typeparam name="TTenantKey">Type that represents the tenant key.</typeparam>
 /// <param name="context">Context that has multi-tenancy configured and is calling SaveChanges() or SaveChangesAsync().</param>
 /// <param name="tenantId">ID of the currently scoped tenant.</param>
 /// <param name="tenancyModelState">The same state object that was passed out of <see cref="ModelBuilder"/>.HasTenancy().</param>
 /// <param name="logger">For logging tenancy access related traces.</param>
 public static void EnsureTenancy <TTenantKey>(this DbContext context, TTenantKey tenantId, TenancyModelState <TTenantKey> tenancyModelState, ILogger logger = null)
     where TTenantKey : class
 {
     context.EnsureTenancy((object)tenantId, tenancyModelState, logger);
 }