[英]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. 我做了一个查询,该查询应该只返回3行,但是我得到了36行,其余都是重复的。
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? 难道是.ToArray导致它有多个重复项?
One quick solution is make use of Distinct method 一种快速的解决方案是使用Distinct方法
string[][] results = query.Distinct().ToArray();
which may resolve your problem. 这可能会解决您的问题。
if not please share the data of you table.... 如果没有,请共享您的表数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.