I am new to using LINQ. I am trying to use it in Silverlight as I’m trying to do a DISTINCT query. My Silverlight application pings a WCF service which returns an ObservableCollection of a custom type. I am trying to get to a DISTINCT record set based on several properties of my custom type. I know the first step is to get my record set, so I’m trying the following
var filteredItems = (from entity in e.Result
select new FilteredItem
{
Property1 = entity.Property1,
Property2 = entity.Property2,
Property3 = entity.Property3
}).Distinct();
Unfortunately, this doesn’t work. Intellisense gives me an error that says “Could not find an implementation of the query pattern for source type MyServiceProxy.MyCustomType. Select not found…” How can I use an ObservableCollection with LINQ, or get this distinct set like I’m showing?
Thank you!
ObservableCollection<T>implementsIEnumerable<T>, so you should be able to do that if you’reusing System.Linq. All the standard LINQ operators reside in that namespace. If that doesn’t work, then make sure you’re referencing System.Core.dll, because that’s the assembly that contains those same implementations.