0
我正在MVC4中创建一个应用程序。我的模型如下:我收到以下错误代码,如何解决?
public class NonComplianceData
{
public static List<MonthDefinitions> Months = new List<MonthDefinitions>()
{
new MonthDefinitions {Month = "January", Order = 1},
new MonthDefinitions {Month = "February", Order = 2},
new MonthDefinitions {Month = "March", Order = 3},
new MonthDefinitions {Month = "April", Order = 4},
new MonthDefinitions {Month = "May", Order = 5},
new MonthDefinitions {Month = "June", Order = 6},
new MonthDefinitions {Month = "July", Order = 7},
new MonthDefinitions {Month = "August", Order = 8},
new MonthDefinitions {Month = "September", Order = 9},
new MonthDefinitions {Month = "October", Order = 10},
new MonthDefinitions {Month = "November", Order = 11},
new MonthDefinitions {Month = "December", Order = 12},
};
public int InspectorId { get; set; }
public string InspectorName { get; set; }
public IEnumerable<MonthData> FullYearData { get; set; }
}
public class MonthDefinitions
{
public string Month { get; set; }
public int Order { get; set; }
}
public class MonthData
{
public string Month { get; set; }
public int TotalAuditsCompleted { get; set; }
public int TotalNoDefects { get; set; }
public decimal NonComplianceRate
{
get
{
if (TotalAuditsCompleted == 0)
{
return 0;
}
else
{
return (TotalNoDefects/(decimal)TotalAuditsCompleted) * 100;
}
}
}
}
我想用下面的填充数据:
var inspectorData =
context.COESDetails
.Where(x =>
x.UploadCOESDetails.AuditZoneId == criteria.AuditZoneId &&
x.UploadCOESDetails.AuditMonth.Contains(criteria.AuditYear))
.Select(x => x.Inspector)
.Where(y => y.Id != 0)
.Distinct()
.OrderBy(x => x.Firstname)
.Select(ud => new NonComplianceData
{
InspectorId = ud.Id,
InspectorName = ud.Firstname + " " + ud.Surname,
FullYearData =
NonComplianceData.Months.Select(month =>
new MonthData
{
Month = month.Month,
})
});
,我得到以下错误
基地{} System.SystemException = {“无法创建类型为'AIS.Domain.Models.MonthDefinitions'的常量值 。在此上下文中仅支持基本类型或枚举类型。”}
个
任何帮助,将不胜感激..谢谢
其他注意事项:
,如果我用这个
public static IEnumerable<string> Months =
new string[] { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
问题是固定的,但我需要确保个月排序正确,这就是为什么我添加了订单属性
这个错误发生在哪里? –
只需要知道,为什么不使用枚举器而不是创建列表?编辑:您的列表几个月基本上是一个枚举器,为什么要创建它? –
Vinicius
Simon Whitehead - 检查员发生错误Data – user2206329