{"id":18300802,"url":"https://github.com/stratosblue/cuture.entityframework.dynamicfilter","last_synced_at":"2026-04-24T05:39:21.313Z","repository":{"id":209086588,"uuid":"722496437","full_name":"stratosblue/Cuture.EntityFramework.DynamicFilter","owner":"stratosblue","description":"An extension library for `EntityFrameworkCore` to support dynamic global filters. 一个 `EntityFrameworkCore` 的拓展库，用于支持动态的全局过滤器。","archived":false,"fork":false,"pushed_at":"2026-03-23T06:56:15.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-24T22:46:58.165Z","etag":null,"topics":["dynamic-filter","ef","entity-framework","global-filter"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stratosblue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T09:22:24.000Z","updated_at":"2026-03-23T06:56:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ffe13a0-386b-4480-b3d5-b0930a6e91e3","html_url":"https://github.com/stratosblue/Cuture.EntityFramework.DynamicFilter","commit_stats":null,"previous_names":["stratosblue/cuture.entityframework.dynamicfilter"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stratosblue/Cuture.EntityFramework.DynamicFilter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratosblue%2FCuture.EntityFramework.DynamicFilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratosblue%2FCuture.EntityFramework.DynamicFilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratosblue%2FCuture.EntityFramework.DynamicFilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratosblue%2FCuture.EntityFramework.DynamicFilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stratosblue","download_url":"https://codeload.github.com/stratosblue/Cuture.EntityFramework.DynamicFilter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratosblue%2FCuture.EntityFramework.DynamicFilter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32211382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T03:15:14.334Z","status":"ssl_error","status_checked_at":"2026-04-24T03:15:11.608Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic-filter","ef","entity-framework","global-filter"],"created_at":"2024-11-05T15:13:24.719Z","updated_at":"2026-04-24T05:39:21.292Z","avatar_url":"https://github.com/stratosblue.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Cuture.EntityFramework.DynamicFilter\n## 1. Intro\n\nAn extension library for `EntityFrameworkCore` to support dynamic global filters. 一个 `EntityFrameworkCore` 的拓展库，用于支持动态的全局过滤器。\n\n - 动态全局过滤器;\n - 支持自由组合多个过滤器;\n - 全局过滤器支持排序与位置设置（针对联合索引场景，`EntityFrameworkCore` 的 `QueryFilter` 只能附加到查询头部，对联合索引不友好）;\n - 支持查询时忽略部分过滤器;\n - 目标框架 `net7.0`+;\n\n### NOTE!!!\n - 会替换掉 `EntityFrameworkCore` 的 `IQueryCompiler`, 可能与其它通过此逻辑实现功能的库冲突；\n - 与 `EntityFrameworkCore` 的 `QueryFilter` 属于不同的实现，能够共存，内部实现了对 `EntityFrameworkCore` 的 `IgnoreQueryFilters` 的支持，但只针对单个子查询；\n \n## 2. 快速开始\n\n - 任何已引用 `EntityFrameworkCore` 的项目, 引用包:\n```xml\n\u003cItemGroup\u003e\n  \u003cPackageReference Include=\"Cuture.EntityFramework.DynamicFilter\" Version=\"1.0.0-*\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\n - 配置 `DbContext` 时启用 `DynamicQueryFilter`\n```C#\nservices.AddDbContext\u003cXXXXContext\u003e((IServiceProvider serviceProvider, DbContextOptionsBuilder options) =\u003e\n{\n    //Other options\n    options.UseDynamicQueryFilter();\n});\n```\n\n - 向 `DI` 容器注册并配置全局过滤器\n```C#\nservices.AddEntityFrameworkDynamicQueryFilter(options =\u003e\n{\n    // 配置实体 User 的过滤器\n    options.Entity\u003cUser\u003e(builder =\u003e\n    {\n        //添加头部表达式过滤器，表达式过滤器根据查询时 ServiceProvider 中的服务状态动态构造，表达式将在查询 User 时拼接到查询头部\n        builder.AddHeadFilter(provider =\u003e\n        {\n            var currentTenant = provider.GetRequiredService\u003cICurrentTenant\u003e();\n            return currentTenant.Id is null\n                    ? n =\u003e true\n                    : n =\u003e n.TenantId == currentTenant.Id;\n        });\n\n        //添加过滤器 MyQueryFilter（从DI容器中获取），其名称、位置、排序由 MyQueryFilter 内部确定\n        builder.AddFilter\u003cMyQueryFilter\u003e();\n\n        //添加尾部表达式过滤器，其名称为 SoftDeletion，表达式将在查询 User 时拼接到查询末尾\n        builder.AddTailFilter(\"SoftDeletion\", n =\u003e n.IsDeleted == false);\n\n        //Other options\n    });\n});\n```\n\n至此已完成所有配置，在使用对应的 `DbContext` 查询时将会自动应用声明的查询过滤器\n\n-------\n\n## 3. 查询时禁用全局过滤器\n\n - 使用 `EntityFrameworkCore` 的 `IgnoreQueryFilters` 禁用过滤器\n```\nvar query = context.Users.IgnoreQueryFilters();\n```\n\n - 根据名称禁用过滤器\n```\nvar query = context.Users.IgnoreQueryFilter(\"SoftDeletion\");\n```\n\n - 根据过滤器类型禁用过滤器\n```\nvar query = context.Users.IgnoreQueryFilter(typeof(MyClassQueryFilter));\n```\n\n## 4. 实现基于类型的过滤器\n\n实现 `IDynamicQueryFilter\u003cT\u003e` 接口，或直接从 `DynamicQueryFilter\u003cT\u003e`派生；\n\n## 未完待续。。。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstratosblue%2Fcuture.entityframework.dynamicfilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstratosblue%2Fcuture.entityframework.dynamicfilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstratosblue%2Fcuture.entityframework.dynamicfilter/lists"}