Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default query filter #47

Merged
merged 17 commits into from
Oct 24, 2019
Merged

Default query filter #47

merged 17 commits into from
Oct 24, 2019

Conversation

Burgyn
Copy link
Member

@Burgyn Burgyn commented Sep 24, 2019

Closes #42

This PR add capability for applying default filter to every query.


In many cases, we want to define a global filter to apply to each query. For example: ParentId = 1, UserId = ActiveUser.Id, etc.

You can configurate query filter in DatabaseConfiguration class.

public class DatabaseConfiguration : DatabaseConfigurationBase
{
    public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
    {
        modelBuilder.Table("Document")
            .UseQueryFilter<Document>(entity => entity.UserId == 12 && entity.ParentId == 1);
    }
}

KORM will automatically add a condition ((UserId = 0) AND (ParentId = 1)) when calling any query using Query<Document>().

Except for direct sql calls like _database.Query<Document>().Sql("SELECT * FROM DOCUMENT").

⚠️ Configuration over modelBuilder.Table("tableName") is applayed for all entities with tableName. (like Document, DocumentDto, DocumentInfo, ...).

Ignoring global filters

If I need to call a query without these conditions, I must explicitly say:

_database.Query<Document>()
    .IgnoreQueryFilters()
    .ToList();

@Burgyn Burgyn changed the title WIP: Default query filter Default query filter Sep 24, 2019
@Burgyn Burgyn requested a review from satano September 24, 2019 06:02
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/Metadata/ConventionModelMapper.cs Outdated Show resolved Hide resolved
src/Query/IQueryBaseInternal.cs Outdated Show resolved Hide resolved
src/Query/Providers/QueryProvider.cs Outdated Show resolved Hide resolved
@Burgyn Burgyn requested a review from LukasSefcik September 30, 2019 04:16
@Burgyn Burgyn requested review from satano and LukasSefcik October 13, 2019 18:53
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/Query/IQueryBaseInternal.cs Outdated Show resolved Hide resolved
src/Query/IQueryBaseInternal.cs Outdated Show resolved Hide resolved
src/Query/IQueryBaseInternal.cs Outdated Show resolved Hide resolved
src/Query/Expressions/SelectExpression.cs Show resolved Hide resolved
@satano satano force-pushed the defaultQueryFilter branch from 90ced8b to 6e324e3 Compare October 24, 2019 20:02
@satano satano merged commit 6fcd761 into Kros-sk:master Oct 24, 2019
@Burgyn Burgyn deleted the defaultQueryFilter branch October 25, 2019 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global Query Filter
3 participants