35 lines
1008 B
C#
35 lines
1008 B
C#
|
|
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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|