我需要将下面的前后组合成一个结果,然后将其传递给数据 GridView 。我使用 before + after 因为我不知道如何组合结果。
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();
最佳答案
你想要的 +
要么是 before.Concat(after)
要么是 before.Union(after)
,这取决于你想要的方式要处理的重复项(union 删除重复项;concatenation 不删除;例如 {1,2,2,3}
concat {3,4}
is {1 ,2,2,3,3,4}
,其中 {1,2,2,3}
union {3,4}
是 {1,2,3,4}
(虽然顺序是否定义在union case中值得怀疑)
关于c# - 将 2 个查询的结果合并为 1 个结果,然后传递给 DGV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16176577/