{
  "id": "dotnet/ef-core-query-filter-parameter-mismatch",
  "signature": "System.InvalidOperationException: An error was generated for the query filter 'FilterName'. The filter expression must be a LambdaExpression that can be applied to the entity type 'EntityType'.",
  "signature_zh": "System.InvalidOperationException: 为查询过滤器 'FilterName' 生成了错误。筛选器表达式必须是可应用于实体类型 'EntityType' 的 LambdaExpression。",
  "regex": "InvalidOperationException: An error was generated for the query filter.*The filter expression must be a LambdaExpression",
  "domain": "dotnet",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Entity Framework Core query filter uses a parameterized expression that references a property or method not available on the entity's model, often due to a missing navigation property or incorrect lambda syntax.",
  "root_cause_type": "generic",
  "root_cause_zh": "Entity Framework Core 查询过滤器使用了参数化表达式，引用了实体模型上不可用的属性或方法，通常是由于缺少导航属性或 Lambda 语法错误。",
  "versions": [
    {
      "version": "6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Removing the filter entirely may break business logic that requires soft-delete or multi-tenant isolation.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding .Include() to eager-load navigation properties does not fix the filter expression itself; the filter must be corrected at the model level.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the entity's base class or interface does not address the lambda parameter mismatch; the filter must be rewritten.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Rewrite the query filter in OnModelCreating to use a simple lambda without complex expressions. For example, change 'modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == _tenantProvider.GetTenantId())' to 'modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == 1)' and pass the tenant ID via a constructor parameter.",
      "success_rate": 0.85,
      "how": "Rewrite the query filter in OnModelCreating to use a simple lambda without complex expressions. For example, change 'modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == _tenantProvider.GetTenantId())' to 'modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == 1)' and pass the tenant ID via a constructor parameter.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure that any method used in the filter is a static method or property accessible at the model level. Replace instance methods with static equivalents: 'b => b.IsDeleted == false' instead of 'b => _service.IsDeleted(b)'.",
      "success_rate": 0.8,
      "how": "Ensure that any method used in the filter is a static method or property accessible at the model level. Replace instance methods with static equivalents: 'b => b.IsDeleted == false' instead of 'b => _service.IsDeleted(b)'.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Rewrite the query filter in OnModelCreating to use a simple lambda without complex expressions. For example, change 'modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == _tenantProvider.GetTenantId())' to 'modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == 1)' and pass the tenant ID via a constructor parameter.",
    "Ensure that any method used in the filter is a static method or property accessible at the model level. Replace instance methods with static equivalents: 'b => b.IsDeleted == false' instead of 'b => _service.IsDeleted(b)'."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/ef/core/querying/filters",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}