The first solution will be the fastest.
Adding and removing an object from ObservableCollectionis pretty slow. The remove-and-add operation will increment 2 events CollectionChanged.
The problem with the first solution may be a search. You can use a more sophisticated search algorithm, or you can use a dictionary so that your objects are indexed by id.
For instance:
class ComplexObj
{
public int Id{get;set;}
public string SomeProperty{get;set;}
}
Dictionary<int, ComplexObj> lookup = new Dictionary<int, ComplexObj>();
ObservableCollection<ComplexObj> myCollection = new ObservableCollection<ComplexObj>();
When you add an item to the collection, be sure to add it to the dictionary:
public void AddNewObj(ComplexObj obj)
{
lookup.Add(obj.Id, obj);
myCollection.Add(obj);
}
, :
public void Update(ComplexObj obj)
{
lookup[obj.Id].SomeProperty = obj.SomeProperty;
}