0

データベース内で電話番号が重複しているすべてのディーラーを探しています。次に、すべてのディーラー情報を含むレポートにそれらをリストしたいと思います。select ステートメントにディーラー レコード属性を設定するのに問題があります。

ディーラー名住所など 4 番目。group by がそれを制限しているためだと思います。

var dealers = _db.Dealers
            .Where(x => x.Active)
            .GroupBy(x => x.Phone)
            .Select(x => new { Dealer = x.Key, Phone = x.Count()})
            .Where(x => x.Phone > 1);

編集: 望ましい出力は、各ディーラーのリストです。同じ電話番号の販売店を並べて表示したい。電話番号に基づいて重複していないレコードは必要ありません。

4

2 に答える 2

0

You're not saying exactly what the expected output and the actual output is, so I don't know what you mean by 'having trouble'. But I spotted one potentially confusing thing:

You're grouping by the Phone (.GroupBy(x => x.Phone)).

So when you do new { Dealer = x.Key, ... the x.Key will refer to the phone number of this group.

于 2013-10-31T13:48:29.340 に答える