views:

303

answers:

1

According to MSDN there is an overload for the ObservableCollection constructor to which you can pass an IEnumerable. According to the very short MSDN page this will make a "Copy" of the Ienumerable.

How do I determine how this will behave? Will the "Copy" be totally independent of the original or will changes made to the Ienumerable (Such as by a linq query) be reflected automatically in the ObservableCollection?

MSDN Page

+4  A: 

This constructor walks through the items in the IEnumerable and adds each one to the ObservableCollection. Once this is finished the new ObservableCollection has nothing more to do with the IEnumerable (except that if you are dealing with a collection of reference types then the ObservableCollection will hold references to the same objects that were supplied by the IEnumerable).

GraemeF
That explains why things seemed odd to me, My Ienumerable is the result of a Linq query. I was expecting to have a "flat" collection of the results of the query but instead I am getting objects like _Employee1 = {System.Data.Linq.EntityRef<OITaskManager.Model.Employee>} I was assuming that since ObserveableCollection does not implement IQueryable that they could not be references. Now I see that you can have two collections containing the same references but implementing different interfaces? You can query the IQueryable and Bind to the ObservableCollection to get the best of both worlds?
Mike B