【发布时间】:2013-04-29 23:29:32
【问题描述】:
我正在尝试编写一个 LINQ 语句,该语句将从表中提取所有项目,其中列类型与用户在下拉菜单中选择的内容相匹配,但如果未找到匹配项,则它会返回表中的所有项目,而不管方式。我已经让它返回与用户选择匹配的所有项目,但我无法弄清楚需要添加哪些代码,因此如果没有找到匹配项,则默认拉取表中的所有项目。
当前代码:
(from i in db.ItemTypeTranslations
join st in db.SectionTranslations
on i.ItemType.SectionID equals st.SectionID
where i.CultureID == 1 && i.ItemType.SectionID == SelectedSection
select new
{
st.SectionID,
st.Title,
i.ItemTypeName
}).ToList();
【问题讨论】:
标签: c# linq entity-framework-5 asp.net-4.5