Skip to content

NodeCollection.Add method imrovement #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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