.AddRange - Need something like .AddRangeUnique

Posts   
 
    
EdL
User
Posts: 51
Joined: 01-Mar-2010
# Posted on: 04-May-2012 17:55:41   

Greetings,

First a question. If I have a collection that I'm populating multipal times through a series of steps and at each step I use .AddRange, what happens if one of the entities in the 'range' is already represented in the target collection? Will a duplicate be added?

If not, cool.

If it will, any suggestions on implementing an .AddRangeUnique method?

Thanks All,

Ed

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-May-2012 04:42:57   

You can simply call:

myCollection.DoNotPerformAddIfPresent = true;
...
myCollection.AddRange(anotherCollection);

You also could use Contexts, which is a more powerful concept, as you can create semantically uniquing contexts among a whole graph, including prefetchPaths.

David Elizondo | LLBLGen Support Team