-2

I need to have endResult to be in descending order by ID and am not sure how that works with c# Linq. Any help would be great.

private void textBox6_Leave(object sender, EventArgs e)
{
    DataClasses3DataContext db = new DataClasses3DataContext();

    int matchedAdd = (from c in db.GetTable<prop>()
                      where c.streetNum.Contains(textBox1.Text) && c.Direction.Contains(textBox2.Text) && c.street.Contains(textBox4.Text) && c.SUFF.Contains(textBox6.Text)
                      select c.ID).Single();

    var before = (from c in db.GetTable<prop>()
                  where c.ID < matchedAdd
                  orderby c.PARCEL descending
                  select c).Take(6);

    var after = (from c in db.GetTable<prop>()
                 where c.ID > matchedAdd
                 orderby c.PARCEL
                 select c).Take(6);

    var endResult = after.Concat(before);

    dgvBRT.DataSource = endResult;

}
korrowan
  • 513
  • 2
  • 15
  • 35
  • Possible duplicate: http://stackoverflow.com/questions/298725/multiple-order-by-in-linq – Jente Rosseel Apr 29 '13 at 17:23
  • Sounds like you didn't even try to solve this problem. Did you look around at *all* as to how to order a sequence using LINQ? – Servy Apr 29 '13 at 17:25
  • @Servy yep I didn't bother to do anything. I just came here and posted without even the slightest attempt . – korrowan Apr 29 '13 at 17:46
  • @korrowan Where did you look? What did you try? What happened as a result of those attempts? Did you get errors, were they compile time or runtime, did you get incorrect outputs, etc? There are *thousands* of tutorials on this subject, so there is a *lot* of information out there that demonstrates *exactly* how to do this. – Servy Apr 29 '13 at 17:48

2 Answers2

2
dgvBRT.DataSource = endResult.OrderByDescending(x => x.ID);

...there's not much else to say.

spender
  • 106,080
  • 28
  • 202
  • 324
1

This may helps:

after.Concat(befor).OrderByDescending(i => i.ID);
Hossein Narimani Rad
  • 27,798
  • 16
  • 81
  • 109