我需要在下面和之后组合成一个结果然后将它传递给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();
答案 0 :(得分:5)
您想要的+
有before.Concat(after)
或before.Union(after)
,具体取决于您希望如何处理重复项(union会删除重复项;连接不会;例如{{1} } concat {1,2,2,3}
是{3,4}
,其中-{1,2,2,3,3,4}
union {1,2,2,3}
是{3,4}
(尽管在联合案例中是否定义了订单仍有疑问)< / p>
答案 1 :(得分:1)
你可以使用union-operator:
var endresult = before.Union(after);