-2

我需要让 endResult 按 ID 降序排列,并且不确定它如何与 c# Linq 一起使用。任何帮助都会很棒。

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;

}
4

2 回答 2

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

……没什么好说的。

于 2013-04-29T17:23:03.373 回答
1

这可能会有所帮助:

after.Concat(befor).OrderByDescending(i => i.ID);
于 2013-04-29T17:23:45.790 回答