【发布时间】:2009-06-24 10:13:19
【问题描述】:
我有一个 Menu 类,它有一个名为 WebPages 的 IQueryable 属性。在以下语句中,我根据匹配返回菜单项,但我需要包含 Webpages 属性。这是我目前拥有的。
var allCategories = Menu.All().Where(x => x.CategoryID == 4 && x.Visible)
我需要扩展它来检查 WebPage 类中的一个属性,像这样..
var allCategories = Menu.All().Where(x => x.CategoryID == 4 && x.Visible && x.WebPages.Roles.Contains(User.Identity.Name))
这不会编译,但我希望你能明白我正在尝试做的事情。
注意:网页属性由 PageID 而非 CategoryID 填充,但不确定这是否有区别??
这是我的课程的简要概述。
public partial class Menu: IActiveRecord
{
public int ID {get; set;}
public int CategoryID {get;set;}
public bool Visible {get;set;}
public int PageID {get;set;}
public IQueryable<WebPage> WebPages
{
get
{
var repo=NorthCadburyWebsite.Models.WebPage.GetRepo();
return from items in repo.GetAll()
where items.ID == _PageID
select items;
}
}
}
public partial class WebPage: IActiveRecord
{
public int ID {get;set;}
public string Roles {get;set;}
}
【问题讨论】:
标签: c# asp.net-mvc linq subsonic