Duplicates in results from .ToArray in LinQ query
I did a query which should return only 3 rows, but I get 36 rows with the rest being duplicates.
开发者_JAVA技巧var query = from a in db.as
join b in db.bs on a.pri equals b.for
join c in db.cs on b.pri equals c.for
where b.Age == age
select new string[]
{
a.Name,
a.Gender,
b.Amount,
c.Location,
};
string[][] results = query.ToArray();
return results;
Could it be the .ToArray causing it to have multiple duplicates?
One quick solution is make use of Distinct method
string[][] results = query.Distinct().ToArray();
which may resolve your problem.
if not please share the data of you table....
精彩评论