{
  "id": "dotnet/ef-core-multiple-navigation-sets",
  "signature": "System.InvalidOperationException: Cannot create a DbSet for 'X' because a DbSet with the same entity type already exists.",
  "signature_zh": "System.InvalidOperationException：无法为 'X' 创建 DbSet，因为已存在具有相同实体类型的 DbSet。",
  "regex": "System\\.InvalidOperationException: Cannot create a DbSet for '[^']+' because a DbSet with the same entity type already exists\\.",
  "domain": "dotnet",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The DbContext class defines two or more DbSet properties that map to the same entity type, causing ambiguity in EF Core's internal model building.",
  "root_cause_type": "generic",
  "root_cause_zh": "DbContext 类定义了两个或更多映射到同一实体类型的 DbSet 属性，导致 EF Core 内部模型构建产生歧义。",
  "versions": [
    {
      "version": "EF Core 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "EF Core 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "EF Core 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This removes the property from the context entirely, losing the ability to query that entity through that property.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This duplicates code and does not solve the core issue of duplicate DbSet definitions.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Remove the duplicate DbSet property from the DbContext class. Keep only one declaration for the entity type. For example, remove either 'public DbSet<Order> Orders { get; set; }' or 'public DbSet<Order> SalesOrders { get; set; }'.",
      "success_rate": 0.95,
      "how": "Remove the duplicate DbSet property from the DbContext class. Keep only one declaration for the entity type. For example, remove either 'public DbSet<Order> Orders { get; set; }' or 'public DbSet<Order> SalesOrders { get; set; }'.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you need multiple query surfaces, use separate DbContext classes for different bounded contexts.",
      "success_rate": 0.8,
      "how": "If you need multiple query surfaces, use separate DbContext classes for different bounded contexts.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "从 DbContext 类中移除重复的 DbSet 属性。只保留一个实体类型声明。例如，移除 'public DbSet<Order> Orders { get; set; }' 或 'public DbSet<Order> SalesOrders { get; set; }' 中的一个。",
    "如果需要多个查询接口，为不同的限界上下文使用单独的 DbContext 类。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/ef/core/modeling/entity-types",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-05-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}