我的 asp.net mvc Web 应用程序中有以下模型类:
public class SecurityRoleGroupAssign
{
public IEnumerable<TechnologyType> TechnologyType {get; set;}
public IEnumerable<PermisionLevel> PermisionLevel {get; set;}
public SecurityRole SecurityRole { get; set; }
public Nullable<int> rackPermisionLevel { get; set; }
public Nullable<int> serverPermisionLevel { get; set; }
public Nullable<int> routerPermisionLevel { get; set; }
public Nullable<int> virtualMachinePermisionLevel { get; set; }
public Nullable<int> switchPermisionLevel { get; set; }
}
但是当我试图填充这个类时,我得到了一个空异常:-
public SecurityRoleGroupAssign populateSecurityRolePermisionLevelAssign(int RoleID)
{
SecurityRoleGroupAssign c = new SecurityRoleGroupAssign
{
SecurityRole = FindAllRole(RoleID),
PermisionLevel = tms.PermisionLevels.ToList(),
TechnologyType = tms.TechnologyTypes.ToList(),
serverPermisionLevel = tms.SecurityroleTypePermisions
.Where(a=>a.SecurityRoleID == RoleID)
.Where(a2=>a2.TechnologyType.Name.ToLower() == "server")
.SingleOrDefault().PermisionLevelID,
rackPermisionLevel = tms.SecurityroleTypePermisions
.Where(a => a.SecurityRoleID == RoleID)
.Where(a2 => a2.TechnologyType.Name.ToLower() == "rack")
.SingleOrDefault().PermisionLevelID,
virtualMachinePermisionLevel = tms.SecurityroleTypePermisions
.Where(a=>a.SecurityRoleID == RoleID)
.Where(a2=>a2.TechnologyType.Name.ToLower() == "virtual machine")
.SingleOrDefault().PermisionLevelID,
routerPermisionLevel = tms.SecurityroleTypePermisions
.Where(a=>a.SecurityRoleID == RoleID)
.Where(a2=>a2.TechnologyType.Name.ToLower() == "router")
.SingleOrDefault().PermisionLevelID,
switchPermisionLevel = tms.SecurityroleTypePermisions
.Where(a => a.SecurityRoleID == RoleID)
.Where(a2 => a2.TechnologyType.Name.ToLower() == "switch")
.SingleOrDefault().PermisionLevelID
};
return c;
}