using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; namespace APT.Infrastructure.EF { internal sealed class TenantModelCacheKey : ModelCacheKey where TDbContext : DbContext, ITenantDbContext { private readonly TDbContext context; private readonly string identifier; public TenantModelCacheKey(TDbContext context, string identifier) : base(context) { this.context = context; this.identifier = identifier; } protected override bool Equals(ModelCacheKey other) { return base.Equals(other) && (other as TenantModelCacheKey)?.identifier == identifier; } public override int GetHashCode() { var hashCode = base.GetHashCode(); if (identifier != null) { hashCode ^= identifier.GetHashCode(); } return hashCode; } } }