{
  "id": "dotnet/ef-core-query-split-query-exception",
  "signature": "System.InvalidOperationException: Cannot use split query for a query that uses Include on a collection navigation that is also used in a Select. Either call AsSplitQuery() before the Include or remove the Select.",
  "signature_zh": "System.InvalidOperationException: 无法对在 Select 中也使用的集合导航上的 Include 使用拆分查询。请在 Include 之前调用 AsSplitQuery() 或移除 Select。",
  "regex": "Cannot use split query for a query that uses Include on a collection navigation that is also used in a Select\\. Either call AsSplitQuery\\(\\) before the Include or remove the Select\\.",
  "domain": "dotnet",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Entity Framework Core throws this when a LINQ query combines 'Include' on a navigation property with a 'Select' that projects the same navigation, conflicting with split query execution mode.",
  "root_cause_type": "generic",
  "root_cause_zh": "当 LINQ 查询在导航属性上组合使用 'Include' 和投影同一导航的 'Select' 时，与拆分查询执行模式冲突，Entity Framework Core 会抛出此异常。",
  "versions": [
    {
      "version": "Entity Framework Core 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Entity Framework Core 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adding 'AsSplitQuery()' after 'Include' does not fix the issue; it must be placed before the Include chain.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Removing 'Include' and relying solely on lazy loading may cause N+1 query problems and performance degradation.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Switching to 'AsSingleQuery()' globally avoids the error but may cause cartesian explosion and slow queries.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Place 'AsSplitQuery()' before the first 'Include' in the query chain: 'var result = context.Orders.AsSplitQuery().Include(o => o.Items).Where(o => o.Id == 1).ToList();'",
      "success_rate": 0.9,
      "how": "Place 'AsSplitQuery()' before the first 'Include' in the query chain: 'var result = context.Orders.AsSplitQuery().Include(o => o.Items).Where(o => o.Id == 1).ToList();'",
      "condition": "",
      "sources": []
    },
    {
      "action": "Replace 'Include' with a 'Select' that explicitly projects the related data: 'var result = context.Orders.Where(o => o.Id == 1).Select(o => new { o.Id, Items = o.Items.Select(i => i.Name) }).ToList();'",
      "success_rate": 0.85,
      "how": "Replace 'Include' with a 'Select' that explicitly projects the related data: 'var result = context.Orders.Where(o => o.Id == 1).Select(o => new { o.Id, Items = o.Items.Select(i => i.Name) }).ToList();'",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在查询链中第一个 'Include' 之前放置 'AsSplitQuery()'：'var result = context.Orders.AsSplitQuery().Include(o => o.Items).Where(o => o.Id == 1).ToList();'",
    "用显式投影相关数据的 'Select' 替换 'Include'：'var result = context.Orders.Where(o => o.Id == 1).Select(o => new { o.Id, Items = o.Items.Select(i => i.Name) }).ToList();'"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/ef/core/querying/single-split-queries#split-queries",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}