Skip to content
This repository was archived by the owner on Apr 5, 2019. It is now read-only.
This repository was archived by the owner on Apr 5, 2019. It is now read-only.

OnModelCreating is cached and filters params is set just once at the first request #24

@rstreit

Description

@rstreit

The documentation is not clear, so I have configured Filters this way:

public CrudContext() : base("name=CrudContext")
{
        int? tenantId = AppManager.GetTenantId();
        if (tenantId.HasValue)
        {
            this.EnableFilter("Tenant").SetParameter("TenantId", tenantId.Value);
        }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
        modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

        DbInterception.Add(new FilterInterceptor());

        modelBuilder.Conventions.Add(FilterConvention.Create<ITenantEntity, int>("Tenant", (e, TenantId) => e.TenantId == TenantId));
}

The first request tenantId is set to 1, the constructor CrudContext and OnModelCreating is called and the filter is applied. The second request tenantId is set to 2, the constructor CrudContext is called and filter value is set to 2, but OnModelCreating is not called, I think it was cached. The filter stay the same tenantId == 1. All next requests diferents value filters are set on constructor CrudContext but filter is never changed, stay the same way wich was already set on the first request.

How should configuration be set to get this working?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions