Skip to content

Commit

Permalink
Merge pull request #388 from DataObjects-NET/6.0-nodecollection-add-impr
Browse files Browse the repository at this point in the history
NodeCollection.Add method imrovement
  • Loading branch information
alex-kulakov authored Apr 2, 2024
2 parents 7b9e17f + 899e526 commit bbd689a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog/6.0.13_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>.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
17 changes: 14 additions & 3 deletions Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ public class NodeCollection<TNode>: CollectionBaseSlim<TNode>
/// <returns><see langword="True"/> if this instance is read-only; otherwise, <see langword="false"/>.</returns>
public override bool IsReadOnly { get { return IsLocked || base.IsReadOnly; } }

/// <inheritdoc/>
/// <summary>
/// Adds item to collection.
/// </summary>
/// <param name="item">Item to add</param>
/// <exception cref="ArgumentException">The item with same name already exists in the collection</exception>
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)
Expand Down

0 comments on commit bbd689a

Please sign in to comment.