cs0815
cs0815

Reputation: 17408

contains ilist nhibernate

I have a class:

public class Author : Entity
{
    public virtual string ForeName { get; set; }
    public virtual string LastName { get; set; }

    public Author() { }
}

and another class X that contains:

public virtual IList<Author> Authors { get; set; }

Is overriding the Equals method in Author the best way to determine whether X already contains an Author?

Upvotes: 1

Views: 63

Answers (1)

Anton
Anton

Reputation: 1583

If you have got list of Authors, as for me the best way to search is dictionary:

var auditors = list.ToDictionary<IdType, Author>(key => key.Id, value => value)
Auditor auditor;
if(auditors.ContainsKey(key))
{
   auditor = auditors[key];
}

OR

Auditor auditor;
if(auditors.TryGetValue(key, out auditor))
{
   ...
}

Upvotes: 1

Related Questions