Skip to content

Commit bbd689a

Browse files
authored
Merge pull request #388 from DataObjects-NET/6.0-nodecollection-add-impr
NodeCollection.Add method imrovement
2 parents 7b9e17f + 899e526 commit bbd689a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

ChangeLog/6.0.13_dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
[main] Join/LeftJoin is denied to have the same expression instance for both inner/outer selector
55
[main] Addressed issue when wrong type of join was chosen when .First/FirstOrDefalult() method was used as subquery
66
[main] Added dedicated exception when RenameFieldHint.TargetType exists in current model but absent in storage model
7+
[main] Xtensive.Sql.Model.NodeCollection<T>.Add() throws understandable exception in case of duplicate name of item
78
[postgresql] Fixed issue of incorrect translation of contitional expressions including comparison with nullable fields

Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ public class NodeCollection<TNode>: CollectionBaseSlim<TNode>
3030
/// <returns><see langword="True"/> if this instance is read-only; otherwise, <see langword="false"/>.</returns>
3131
public override bool IsReadOnly { get { return IsLocked || base.IsReadOnly; } }
3232

33-
/// <inheritdoc/>
33+
/// <summary>
34+
/// Adds item to collection.
35+
/// </summary>
36+
/// <param name="item">Item to add</param>
37+
/// <exception cref="ArgumentException">The item with same name already exists in the collection</exception>
3438
public override void Add(TNode item)
3539
{
3640
base.Add(item);
37-
if (!string.IsNullOrEmpty(item.GetNameInternal()))
38-
nameIndex.Add(item.GetNameInternal(), item);
41+
var name = item.GetNameInternal();
42+
if (!string.IsNullOrEmpty(name)) {
43+
try {
44+
nameIndex.Add(name, item);
45+
}
46+
catch(ArgumentException) {
47+
throw new ArgumentException(string.Format(Strings.ExItemWithNameXAlreadyExists, name));
48+
}
49+
}
3950
}
4051

4152
public override bool Remove(TNode item)

0 commit comments

Comments
 (0)