LINQ query help

Discussion in 'ASP .Net' started by .nLL, Sep 9, 2009.

  1. .nLL

    .nLL Guest

    Hi, i've got below query
    --------------------------
    TopCountriesRepeater.DataSource = ds.Tables[1].AsEnumerable()
    .GroupBy(row => row.Field<string>("CountryCode"))
    .Select(group => new { CountryCode = group.Key, CountryName
    = group.Key, UsersFromIp = group.Sum(row =>
    row.Field<int>("UsersFromIp")) })
    .OrderByDescending(g => g.UsersFromIp);
    -----------------------

    What i want to do is instead of

    CountryName = group.Key

    I want to select "CountryName" column of the row when executing query.
    Can someone give me heads up for this?

    Thanks
     
    .nLL, Sep 9, 2009
    #1
    1. Advertising

  2. .nLL

    miher Guest

    ".nLL" <> az alábbiakat írta a következo üzenetben
    news:JGRpm.87141$2...
    > Hi, i've got below query
    > --------------------------
    > TopCountriesRepeater.DataSource = ds.Tables[1].AsEnumerable()
    > .GroupBy(row => row.Field<string>("CountryCode"))
    > .Select(group => new { CountryCode = group.Key, CountryName
    > = group.Key, UsersFromIp = group.Sum(row =>
    > row.Field<int>("UsersFromIp")) })
    > .OrderByDescending(g => g.UsersFromIp);
    > -----------------------
    >
    > What i want to do is instead of
    >
    > CountryName = group.Key
    >
    > I want to select "CountryName" column of the row when executing query.
    > Can someone give me heads up for this?
    >
    > Thanks
    >
    >


    Hi,

    Try something like :
    CountryName = group.First().Field<...>("...")

    -Zsolt
     
    miher, Sep 10, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ChrisN
    Replies:
    1
    Views:
    565
    Alexey Smirnov
    Aug 7, 2007
  2. shapper

    LINQ Query

    shapper, Oct 17, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    385
    sloan
    Oct 18, 2007
  3. Alex Sauceda

    SQL Query to Linq (Group By and Sum)

    Alex Sauceda, Feb 4, 2008, in forum: ASP .Net
    Replies:
    6
    Views:
    41,228
    Alex Sauceda
    Feb 4, 2008
  4. Joey
    Replies:
    1
    Views:
    735
    bruce barker
    Apr 23, 2008
  5. George

    Linq or not Linq

    George, Nov 4, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    389
    Mike Gleason jr Couturier
    Nov 5, 2008
Loading...

Share This Page