{"record":{"id":"2eaaa20b13643afb","repo":"EllanJiang/GameFramework","slug":"already-exist-0-in-data-table-1","errorCode":null,"errorMessage":"Already exist '{0}' in data table '{1}'.","messagePattern":"Already exist '(.+?)' in data table '(.+?)'\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/DataTable/DataTableManager.DataTable.cs","lineNumber":507,"sourceCode":"            /// <returns>循环访问集合的枚举数。</returns>\n            IEnumerator IEnumerable.GetEnumerator()\n            {\n                return m_DataSet.Values.GetEnumerator();\n            }\n\n            /// <summary>\n            /// 关闭并清理数据表。\n            /// </summary>\n            internal override void Shutdown()\n            {\n                m_DataSet.Clear();\n            }\n\n            private void InternalAddDataRow(T dataRow)\n            {\n                if (m_DataSet.ContainsKey(dataRow.Id))\n                {\n                    throw new GameFrameworkException(Utility.Text.Format(\"Already exist '{0}' in data table '{1}'.\", dataRow.Id, new TypeNamePair(typeof(T), Name)));\n                }\n\n                m_DataSet.Add(dataRow.Id, dataRow);\n\n                if (m_MinIdDataRow == null || m_MinIdDataRow.Id > dataRow.Id)\n                {\n                    m_MinIdDataRow = dataRow;\n                }\n\n                if (m_MaxIdDataRow == null || m_MaxIdDataRow.Id < dataRow.Id)\n                {\n                    m_MaxIdDataRow = dataRow;\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/DataTable/DataTableManager.DataTable.cs#L489-L525","documentation":"Thrown by DataTable<T>.InternalAddDataRow (invoked via AddDataRow) when a row with the same Id already exists in the table. Rows are keyed by their Id in m_DataSet, so duplicates would silently overwrite data and are rejected instead.","triggerScenarios":"Calling AddDataRow twice with rows whose DataRow Id is identical; loading two data files that both contain a row with the same primary key.","commonSituations":"Merging exported files from different sources; idempotent re-load of the same table without clearing it first; copy-pasted row in the spreadsheet with the same key column.","solutions":["Fix the source data so each row has a unique Id.","Check HasDataRow(id) before adding and skip or update duplicates.","Call Clear() on the table before reloading the same dataset."],"exampleFix":"// before\ntable.AddDataRow(row1); // Id = 42\ntable.AddDataRow(row2); // Id = 42 -> throws\n// after\nif (!table.HasDataRow(42)) table.AddDataRow(row2); else /* update/skip */ ;","handlingStrategy":"validation","validationCode":"if (table.HasDataRow(row.Id)) { /* update or skip */ } else { table.AddDataRow(row); }","typeGuard":null,"tryCatchPattern":"try { table.AddDataRow(row); } catch (GameFrameworkException ex) when (ex.Message.Contains(\"Already exist\")) { Log.Warn($\"Duplicate id {row.Id} in {table.Name}\"); }","preventionTips":["Enforce unique primary-key column in source spreadsheets","Call HasDataRow before adding","Clear() the table before full reloads","Deduplicate when merging multiple data sources"],"tags":["csharp","datatable","duplicate-key"],"backgroundTag":"file-already-exists","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}