I wonder why I am not able to find this error on stackoverflow. In Linq to SQL, i am selecting an anonymous object like
var something = from a in .....
......
......
select new {
myParameter = a.Something
myListParameter = (from b in ........
select b)
}
.
.
.
.
something = something.Distinct(); //This is giving error
In selecting anonymous type object above, in one of the properties I am selecting another list. I guess this might be causing the issue. I wonder if there is a workaround.
It may be because your query is returning more than one result,
try using
something = something.Distinct().ToList();
You can use a workaround if applicable to your requirements .
something = something.GroupBy(x => x.PropertyToCompare).Select(x => x.First());
there is no way to Distinct() an anonymous type as each object will be held in different memory space, and therefore not equatable.
You will likely need to implement IEquatable to use Distinct() as per this response: Distinct not working with LINQ to Objects