nAll right guys, this one is one of the shortest blog post I am doing today and hope it helps people like me who wasted almost few minutes searching for solution on this.
n
nBasically .NET Framework offers us too many collections however two of those are
n1. List
n2. Collection
n
nWe all know Linq, i.e. this nice and slick feature of .NET to query various collections however when it comes to Collections then we get this famous typecasting error
ni..e Cannot convert IEnumerable to Collection etc etc..
n
nWell, after several minutes of discussion with my brainy peers and some search on internet here is what I have done
n
nIts a workaround which works in two steps
n1. Convert your Collection to List and perform Linq on it.
n2. Convert back your List to Collection. How? here we go
n
nCollection<Entity> collection = new ObservableCollection<Entity>(collection.ToList().Distinct());
n
nAnd you are done.
n
nHope this helps someone.
n
nBasically .NET Framework offers us too many collections however two of those are
n1. List
n2. Collection
n
nWe all know Linq, i.e. this nice and slick feature of .NET to query various collections however when it comes to Collections then we get this famous typecasting error
ni..e Cannot convert IEnumerable to Collection etc etc..
n
nWell, after several minutes of discussion with my brainy peers and some search on internet here is what I have done
n
nIts a workaround which works in two steps
n1. Convert your Collection to List and perform Linq on it.
n2. Convert back your List to Collection. How? here we go
n
nCollection<Entity> collection = new ObservableCollection<Entity>(collection.ToList().Distinct());
n
nAnd you are done.
n
nHope this helps someone.