【发布时间】:2014-06-23 11:06:21
【问题描述】:
我有一个新问题,或者我只是有点卡住了我的头。
我有几个 DropDownLists。在那里你可以选择一个值或什么都没有。两者对于选择值后的 LINQ 语句中的 where 子句都很重要。所以我需要的是,如果你选择了一个值,它应该说(例如):
var result = from c in context.table
where c.name == dropdown.selectedvalue
select c.id;
这是更容易的部分。所以我的问题是,如果您在下拉列表中选择了 null/empty 字段,它应该给我来自数据库的每个结果。与上面相同的语句类似,但没有 where 子句。
我最大的问题是,我有 4 个不同的 DropDownLists,每个 List 都是 where 子句的一个元素。我的 LINQ 语句长约 30 行,我不想为每种情况复制语句 5 次。
var finishedReports = (from r in context.response
from c in context.maxCTs
from t in context.ticket
join tp in context.priorities
on t.ticket_priority_id equals tp.id
join ts in context.states
on t.ticket_state_id equals ts.id
from a in context.article
where (from ti in context.ticket
where ti.tn == r.tn
select new { ti.id }).Contains(new { id = a.ticket_id })
where r.change_time >= startdat &&
r.change_time <= enddat &&
r.tn == c.tn &&
t.tn == r.tn
//where t.queue_id == queueID &&
// tp.id == priority &&
// ts.name.Contains(status)
orderby r.tn
select new
{
r.tn,
r.title,
a.id,
a.a_subject,
a.article_type_id,
a.a_from,
tp.id,
ts.name,
r.change_time,
r.start_date,
r.create_date,
c.finish_date
}).Distinct();
当从 DropDownList 中选择的值为空或为空时,我如何在语句中写入它应该从数据库中获取每个数据? (上面代码中的注释行是比较下拉列表中的值的 where 子句)
感谢您的每一个帮助,如果我的问题令人困惑,我会改变它!
【问题讨论】: