linq distinct and select new query
Assuming that different Ids are always considered distinct you can try this.
I would probably write it in two querys. That way it is easy to debug and more readable. You can use MoreLinq
.
DistinctBy
Download
var temp = from a in QProductAllInfo select new { a.Id, a.Title, a.FullTitle}.ToList();
var result = temp.DistinctBy(i => i.Id);
You can also use
Var result = temp.GroupBy(x => x.Id).Select(y => y.First());
If you have duplicates in QProductAllInfo, replacing your code by this should fix your problem.
var QP = from a in QProductAllInfo.Distinct()
select new { a.Id, a.Title, a.FullTitle };
if this doesn't work, you can use tuples instead of anonymous types like this:
var QP = from a in QProductAllInfo
select Tuple.Create(a.Id, a.Title, a.FullTitle);
Applying the Distinct operator on anonymous types is useless because anonymous types are always reference types that donc implement the IEquatable interface.