help don't succeed in getting right data in my repeater

Last post 05-16-2008 10:15 AM by Jeev. 1 replies.

Sort Posts:

  • help don't succeed in getting right data in my repeater

    05-16-2008, 9:45 AM
    • Loading...
    • keetje
    • Joined on 05-14-2008, 11:43 AM
    • Posts 5

    I am trying to show names and counts in a repeater.

    Have two tables here. Votes and Medicines. Votes has the votes and a foreign key (FK_MedicineID) to the Medicine table.

    I want to show the medicines with the most votes in a repeater (take the first 3)

    It works when i just want to show the FK_MedicineID, but I want to make the join to the Medicinetable and show the MedicineName...

    Somehow I don't see how to do this, because I use the select new { ... }; in my query.

    THis is my code:

    MMDataContext db = new MMDataContext(strConnection);

    var qmed = from vote in db.Votes
                    
    group vote by vote.FK_MedicineID into g
                    
    orderby g.Count() descending
                     
    select new { MedId = g.Key, Count = g.Count() };

    var medmostvotes = qmed.Take(3);

    Repeater1.DataSource = medmostvotes;
    Repeater1.DataBind();

    In my select new I want to add something like MedName = ....

    But don't see how.

    Any suggestions?

    Thanks

  • Re: help don't succeed in getting right data in my repeater

    05-16-2008, 10:15 AM
    Answer
    • Loading...
    • Jeev
    • Joined on 11-24-2005, 7:49 AM
    • Posts 2,258
    MMDataContext db = new MMDataContext(strConnection);

    var qmed = from vote in db.Votes
                    
    group vote by vote.FK_MedicineID into g
                    
    orderby g.Count() descending
                     
    select new { MedId = g.Key, Count = g.Count() };

    var final = from item in qmed

                  join meditem in db.MedicineTable on item.Medid equals meditem.Medid

                  select new {Name =meditem.Name, Count= item.Count};

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
Page 1 of 1 (2 items)