0

私は国=>リーグ=>チーム(名前、スコア)を持っています

国からすべてのチームの Name-Scores を選択する必要があります。

このようなものは機能しません)

query = from ligue in myCountry.Ligues, from team in ligue.Teams select name = team.Name , score = team.Score distinct

編集:

VB.NET 構文が推奨されます。

4

3 に答える 3

4

単純な Select / SelectMany を実行できるはずです

context.Countries.Single(c => c.CountryName == "My Country")
    .Ligues.SelectMany(ligue => ligue.Teams
        .Select(team => new { team.Name, team.Score }))
        .Distinct();
于 2011-09-05T12:35:49.773 に答える
3

VB10 拡張メソッドの構文に変換された Kirk のコードを次に示します。

dim result = context.Countries.Single(Function(c) c.CountryName = "My Country").
               Ligues.SelectMany(Function(ligue) ligue.Teams).
                      Select(Function(team) new with {team.Name, team.Score }).
                      Distinct()

このvb.netクエリ構文のように書くことができると思います(ただし、今はVBコンパイラにアクセスできません)。

(EDIT 私の元のトライアルは確かに間違っていたので、以下のクエリを修正しました:)

dim result = From ligue in myCountry.Ligues
             From team in ligue.Teams
             Select team.Name, team.Score Distinct
于 2011-09-05T14:09:45.537 に答える
1

Kirk のコードを使用した jeroenh のコードを使用すると、ここに作業バージョン (VB.NET) があります。

  Dim query =  From ligue In myCountry.Ligues
               From team In ligue.Teams
               Select Name = team.Name, Score = team.Score 
               Distinct
于 2011-09-05T14:46:40.930 に答える