奥基,最后编辑,承诺:
课程如下:
public partial class MembershipModule : BaseConnection<MembershipModule>
{
private const string AccessPrivilege = "Access";
public bool Accessible()
{
return this.Privileges().Any(p => p.Name.Equals(AccessPrivilege));
}
public IQueryable<MembershipAction> Privileges()
{
var privileges = from p in LinqUtil.Context.MembershipModuleActions
where
p.MembershipModule.Id.Equals(this.Id) &&
p.MembershipRolePrivileges.Any(rp => rp.ModuleActionId.Equals(p.Id))
select p.MembershipAction;
return privileges;
}
}
为什么这项工作
public static List<MembershipModule> Collection()
{
List<MembershipModule> collection = new List<MembershipModule>();
if(!MembershipUser.Connected)
return collection;
foreach(MembershipModule m in LinqUtil.Context.MembershipModules)
{
if(m.Accessible())
collection.Add(m);
}
return collection;
}
虽然如此?
public static List<MembershipModule> Collection()
{
if(!MembershipUser.Connected)
return new List<MembershipModule>();
return LinqUtil.Context.MembershipModules.Where(m => m.Accessible()).ToList();
}