سؤال

I have Country=>Ligue=>Team(Name, Score)

I need to select all team Name-Scores from a country.

something like this, does not work )

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

EDIT:

VB.NET syntax is preferable.

هل كانت مفيدة؟

المحلول 3

Using jeroenh's code, that used Kirk's code, here is the working version (VB.NET)

  Dim query =  From ligue In myCountry.Ligues
               From team In ligue.Teams
               Select Name = team.Name, Score = team.Score 
               Distinct

نصائح أخرى

You should be able to do a simple Select / SelectMany

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

Here's the code from Kirk translated to VB10 extension method syntax:

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()

I believe (but am not sure, don't have access to a VB compiler right now) you can write it like this vb.net query syntax

(EDIT my original trial was indeed incorrect, so I corrected the query below:)

dim result = From ligue in myCountry.Ligues
             From team in ligue.Teams
             Select team.Name, team.Score Distinct
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top