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