このエラーは私を夢中にさせています。以前は機能していました。今はそうではありません。何が原因なのかわからず、多くのものを失うことなくロールバックすることはできません。
Unable to cast object of type 'System.Collections.Generic.List`1[Literrater.Models.ranges]'
to type 'Literrater.Models.ranges'.
これがモデルです。
public class Comment
{
[Key]
public int CommentID { get; set; }
public int ProjectDocID { get; set; }
public int UserID { get; set; }
public string text { get; set; }
public string quote { get; set; }
public DateTime DateCreated { get; set; }
public virtual ICollection<CommentVote> CommentVote { get; set; }
public virtual ICollection<CommentReply> CommentReply { get; set; }
public virtual ICollection<CommentReport> CommentReport { get; set; }
public ProjectDoc ProjectDoc { get; set; }
public virtual User User { get; set; }
public ICollection<ranges> ranges { get; set; }
}
public class ranges
{
public int ID { get; set; }
public string start { get; set; }
public string end { get; set; }
public string startOffset { get; set; }
public string endOffset { get; set; }
}
エラーをスローするアクション
[HttpPost, ActionName("Create")]
public ActionResult Create(Comment comment)
{
comment.DateCreated = DateTime.Now;
comment.UserID = WebSecurity.CurrentUserId;
db.Comments.Add(comment); //Error here
db.SaveChanges();
return Json(comment);
Jsonが投稿されています。
{"text":"",
"ranges":
[{
"start":"/p[1]",
"startOffset":160,
"end":"/p[1]",
"endOffset":234
}],
"quote":"es. Hadn't they ever heard of potpourri? Each incessant beep, made by the",
"UserID":"6",
"ProjectDocID":"1"
}
更新: 古い作業データベースのスクリーンショット