我有一个表单,可以根据他们选择的内容过滤数据。
我正在尝试将 linq 查询彼此附加,以便最终结果是他们在屏幕上选择的结果。
这是我的代码:
private void button_Search_Click(object sender, EventArgs e)
{
using (var model = new SuburbanPortalEntities())
{
var qry = from logs in model.Logs
select logs;
Guid corpid;
if (Guid.TryParse(textBox_CorporationGuid.Text, out corpid))
{
qry = from logs in model.Logs
where logs.CorporationId == corpid
select logs;
}
Guid tokenid;
if (Guid.TryParse(textBox_TokenId.Text, out tokenid))
{
qry = from logs in model.Logs
where logs.TokenId == tokenid
orderby logs.LogDateTime descending
select logs;
}
if (checkBox_DisplayErrors.Checked)
{
qry = from logs in model.Logs
where logs.IsException
select logs;
}
if (checkBox_DisplayWarnings.Checked)
{
qry = from logs in model.Logs
where logs.IsWarning
select logs;
}
dataGridView1.DataSource = qry;
}
}
我没有运气。最后一个 qry 是我的 datagridview 上显示的内容。
有人可以告诉我我做错了什么吗?
谢谢 !