From e3d24b6668d610cef9d630010350e319d62241f9 Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Thu, 28 Mar 2024 12:07:35 +0500 Subject: [PATCH] NodeCollection: Better error exception on adding items with same name --- Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs b/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs index 5b71980c3b..8f4c4d278c 100644 --- a/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs +++ b/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs @@ -30,12 +30,18 @@ public class NodeCollection: CollectionBaseSlim /// if this instance is read-only; otherwise, . public override bool IsReadOnly { get { return IsLocked || base.IsReadOnly; } } - /// + /// + /// Adds item to collection. + /// + /// Item to add + /// The item with same name already exists in the collection public override void Add(TNode item) { base.Add(item); - if (!string.IsNullOrEmpty(item.GetNameInternal())) - nameIndex.Add(item.GetNameInternal(), item); + var name = item.GetNameInternal(); + if (!string.IsNullOrEmpty(name) && !nameIndex.TryAdd(name, item)) { + throw new ArgumentException(string.Format(Strings.ExItemWithNameXAlreadyExists, name)); + } } public override bool Remove(TNode item)