Trying to store results from a LINQ query into ObservableCollection but the results from linq are of decimal type.
ObservableCollection<string> cost =
new ObservableCollection<string>((from i in context.Items
where i.Cost != null
&& i.Cost > 0
orderby i.Cost
select i.Cost).Distinct());
It doesn't compile saying 'The best overloaded method match for 'System.Collections.ObjectModel.ObservableCollection<string>.ObservableCollection(System.Collections.Generic.IEnumerable<string>)' has some invalid arguments.
I looked here but it didn't help me much.
UPDATE
I have tried the following with no success:
ObservableCollection<string> cost =
new ObservableCollection<string>((from i in context.Items
where i.Cost != null
&& i.Cost > 0
orderby i.Cost
select i.Cost).Distinct()
.Select(i=>i.ToString()));
and
ObservableCollection<string> cost =
new ObservableCollection<string>((from i in context.Items
where i.Cost != null
&& i.Cost > 0
orderby i.Cost
select i.Cost.ToString()).Distinct());
When I run both in LINQPad, I get the following error:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
Message LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.