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

Global Query Filter #42

Closed
8 of 10 tasks
Burgyn opened this issue Aug 9, 2019 · 0 comments · Fixed by #47
Closed
8 of 10 tasks

Global Query Filter #42

Burgyn opened this issue Aug 9, 2019 · 0 comments · Fixed by #47
Assignees
Milestone

Comments

@Burgyn
Copy link
Member

Burgyn commented Aug 9, 2019

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

It would be great to be able to define it in one place and KORM would automatically add this condition to every query.

public class DatabaseConfiguration : DatabaseConfigurationBase
{
    public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
    {
        modelBuilder.Entity<Document>()
            .UseQueryFilter(entity => entity.IsDeleted == false && entity.ParentId == 1);
    }
}

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

It should be possible to do this in all scenarios except for direct sql calls _database.Query<Document>().Sql("SELECT * FROM DOCUMENT");

Ignoring global filters

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

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

Things to think about

  • We can have multiple classes to retrieve data from the same table. For example: DocumentHeader, DocumentVerySpecialDto, etc. It would be nice to define this filter for all these classes.

  • Create prototype

  • Allow append where to existing where

  • Configuration

  • Add necessery information into query provider

  • Use defined filter

  • Ignore query filter

  • Unit and integration tests

  • Xml comments

  • Information to readme file.

  • Add info into KORM.MsAccess. (Constructor of QueryProvider was changed).

@Burgyn Burgyn self-assigned this Aug 9, 2019
@Burgyn Burgyn added enhancement New feature or request help wanted Extra attention is needed labels Aug 9, 2019
@Burgyn Burgyn added this to the Version 4.0.0 milestone Aug 9, 2019
@Burgyn Burgyn removed the help wanted Extra attention is needed label Aug 9, 2019
@ghost ghost added the Pending PR label Sep 24, 2019
@ghost ghost removed Pending PR enhancement New feature or request labels Oct 24, 2019
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 a pull request may close this issue.

1 participant