0

我有 Country=>Ligue=>Team(Name, Score)

我需要从一个国家/地区选择所有团队名称分数。

像这样的东西,不起作用)

查询 =来自 myCountry.Ligues 中的ligue,来自 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

下面是从 Kirk 翻译成 VB10 扩展方法语法的代码:

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 编译器)你可以像这个 vb.net 查询语法一样编写它

(编辑我原来的试验确实不正确,所以我更正了下面的查询:)

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

使用 jeroenh 的代码,使用 Kirk 的代码,这里是工作版本(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 回答