开发者

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....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜