将2个查询的结果合并为1个结果,然后传递给DGV

kor*_*wan 1 c# linq

我需要在下面之前和之后组合成一个结果然后将它传递给datagridview.因为我不知道如何组合结果,我之前和之后使用过.

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

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

        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 = before + after;

        dgvBRT.DataSource = endResult;
        dgvBRT.Databind();
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 5

+你想有两种before.Concat(after)或者before.Union(after),这取决于你如何想重复进行处理(联合删除重复;串联不;例如{1,2,2,3}CONCAT {3,4}{1,2,2,3,3,4},在这里,因为{1,2,2,3}工会{3,4}{1,2,3,4}(虽然它是有疑问的顺序在工会的情况下定义)