From 17939b9d4965ca1e3f191b0ba986b1126c054de6 Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Tue, 2 Apr 2024 15:16:39 +0500 Subject: [PATCH 1/2] Better exception on adding item with existing name to node collection --- Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs b/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs index 093774af4e..aadb24e4e0 100644 --- a/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs +++ b/Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs @@ -30,12 +30,23 @@ 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)) { + try { + nameIndex.Add(name, item); + } + catch(ArgumentException) { + throw new ArgumentException(string.Format(Strings.ExItemWithNameXAlreadyExists, name)); + } + } } public override bool Remove(TNode item) From 899e52683ac632844a59092170106bdec62a7b79 Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Tue, 2 Apr 2024 16:52:21 +0500 Subject: [PATCH 2/2] Imrprove changelog --- ChangeLog/6.0.13_dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog/6.0.13_dev.txt b/ChangeLog/6.0.13_dev.txt index d2d9482215..a1a88f9563 100644 --- a/ChangeLog/6.0.13_dev.txt +++ b/ChangeLog/6.0.13_dev.txt @@ -4,4 +4,5 @@ [main] Join/LeftJoin is denied to have the same expression instance for both inner/outer selector [main] Addressed issue when wrong type of join was chosen when .First/FirstOrDefalult() method was used as subquery [main] Added dedicated exception when RenameFieldHint.TargetType exists in current model but absent in storage model +[main] Xtensive.Sql.Model.NodeCollection.Add() throws understandable exception in case of duplicate name of item [postgresql] Fixed issue of incorrect translation of contitional expressions including comparison with nullable fields \ No newline at end of file