protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Owned <Domain.ValueObjects.Localization.LocalizedValueObject>();

            foreach (var entityType in modelBuilder.Model.GetEntityTypes())
            {
                Type TEntity     = entityType.ClrType;
                Type TPrimaryKey = TEntity.GetProperty("Id")?.PropertyType;

                if (TPrimaryKey is null)
                {
                    continue;
                }

                if (EntityExtensions.EntityIsMayHaveTenant(TEntity, TPrimaryKey))
                {
                    modelBuilder.Entity(TEntity)
                    .HasOne(TEntity, "TenantlessEntity")
                    .WithMany("TenantEntities")
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasForeignKey("TenantlessEntityId")
                    .IsRequired(false);
                }

                typeof(EfCoreDbContextBase)
                .GetMethod(nameof(ApplyBaseFilters), BindingFlags.Instance | BindingFlags.NonPublic)
                .MakeGenericMethod(TEntity, TPrimaryKey)
                .Invoke(this, new object[] { modelBuilder, entityType });
            }
        }
        protected virtual void ApplyBaseFilters <TEntity, TPrimaryKey>(ModelBuilder modelBuilder, IMutableEntityType entityType)
            where TEntity : class, IEntity <TPrimaryKey>
        {
            bool isSoftDelete        = typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity));
            bool isMayHaveTenantType = EntityExtensions.EntityIsMayHaveTenant(typeof(TEntity), typeof(TPrimaryKey));
            bool isMustHaveTenant    = typeof(IMustHaveTenant).IsAssignableFrom(typeof(TEntity));

            bool shouldApplyBaseFilters() => isSoftDelete || isMayHaveTenantType || isMustHaveTenant;

            if (entityType.BaseType == null && shouldApplyBaseFilters())
            {
                var baseFiltersExpression = CreateBaseFiltersExpression <TEntity, TPrimaryKey>(
                    isSoftDelete,
                    isMayHaveTenantType,
                    isMustHaveTenant
                    );
                if (baseFiltersExpression != null)
                {
                    modelBuilder.Entity <TEntity>().HasQueryFilter(baseFiltersExpression);
                }
            }
        }