我添加了以下两个模型视图类:
public class AssetCount
{
public int CustomerCount { get; set; }
public int DataCenterCount { get; set; }
public int FirewallCount { get; set; }
public int RouterCount { get; set; }
public int VirtualMachineCount { get; set; }
public int ServerCount { get; set; }
public int StorageDeviceCount { get; set; }
public int RackCount { get; set; }
public int SwitchCount { get; set; }
public int CustomCount { get; set; }
}
public class SystemInformation
{
public AssetCount AssetCount { get; set; }
public ICollection<TechnologyAudit> TechnologyAudit { get; set; }
public ICollection<AdminAudit> AdminAudit { get; set; }
public ICollection<Technology> LatestTechnology { get; set; }
}
但是,在我的模型类方法中,我无法访问AssetCount对象的属性,例如:
public SystemInformation GetSystemInfo(int pagesize)
{
SystemInformation s = new SystemInformation()
{
AssetCount.CustomerCount = entities.AccountDefinitions.Count() //I can not access the CustomerCount !!!!
所以有人可以告诉我这是什么问题吗?感谢。
答案 0 :(得分:9)
您必须先初始化AssetCount
属性:
SystemInformation s = new SystemInformation()
{
AssetCount = new AssetCount { CustomerCount = entities.AccountDefinitions.Count() }
};