Skip to content
This repository has been 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

Open
rstreit opened this issue May 19, 2016 · 1 comment

Comments

@rstreit
Copy link

rstreit commented May 19, 2016

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?

@rstreit rstreit changed the title OnModelCreating is cached and filters params is set just once at firs request OnModelCreating is cached and filters params is set just once at first request May 19, 2016
@rstreit rstreit changed the title OnModelCreating is cached and filters params is set just once at first request OnModelCreating is cached and filters params is set just once at the first request May 19, 2016
@schuettecarsten
Copy link

Same problem here :-(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants