我创建了以下代码:
var header = "Entity Validation Error";
var detail = < I want to have a list that contains the title and errors list here>
foreach (var eve in ex.EntityValidationErrors)
{
var title = string.Format("Entity of type \"{0}\" in state \"{1}\"
has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
System.Diagnostics.Debug.WriteLine(title);
var errors = new List<string>();
foreach (var ve in eve.ValidationErrors)
{
var error = string.Format("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
errors.Add(error);
System.Diagnostics.Debug.WriteLine(error);
}
}
return Request.CreateErrorResponse(HttpStatusCode.Conflict,
< I want to return the header and detail as an anonymous object >);
它检查我的每个实体错误,打印调试消息,创建标题和详细信息列表。
如何将变量标题和错误作为匿名对象并将其放入列表中以便我可以返回它们?