mh_frame_sps/APT.Infrastructure.EF/TenantModelCacheKey.cs

35 lines
1008 B
C#
Raw Permalink Normal View History

2026-04-07 13:47:52 +08:00
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace APT.Infrastructure.EF
{
internal sealed class TenantModelCacheKey<TDbContext> : 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<TDbContext>)?.identifier == identifier;
}
public override int GetHashCode()
{
var hashCode = base.GetHashCode();
if (identifier != null)
{
hashCode ^= identifier.GetHashCode();
}
return hashCode;
}
}
}