2013-04-29 56 views
-2

我需要endResult以ID降序排列,我不确定c#Linq是如何工作的。任何帮助都会很棒。由C#Concat分组?

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; 

} 
+0

可能重复:http://stackoverflow.com/questions/298725/multiple-order-by-in-linq – 2013-04-29 17:23:39

+0

听起来你甚至没有试图解决这个问题问题。你有没有在*全部*四处看看如何使用LINQ订购一个序列? – Servy 2013-04-29 17:25:42

+0

@Servy yep我什么也没做。我刚来这里,并没有丝毫尝试。 – korrowan 2013-04-29 17:46:25

回答

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

...没有太多好说的。

+0

谢谢你们。我不知道该把订单放在哪里......谢谢! – korrowan 2013-04-29 17:25:55

+0

@korrowan:别忘了接受。 – Neolisk 2013-04-29 17:46:07

1

这可能帮助:

after.Concat(befor).OrderByDescending(i => i.ID);