0
我需要他的FIO得到面试官的ID获得从数据库(ASP.NET)ID
我有表有这位模特
[Key]
public int Interwier_id { get; set; }
public string FIO { get; set; }
public string Email { get; set; }
public string Telephone { get; set; }
[DataType(DataType.Date)]
public int Birthday { get; set; }
public string City { get; set; }
public string Salary { get; set; }
public string English { get; set; }
public Nullable<int> Interview_Id { get; set; }
public string Status { get; set; }
public string Position { get; set; }
public string Current_work { get; set; }
public int Age { get { return DateTime.Now.Year - Birthday; } }
public virtual Interview Interview { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Link> Links { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Comment> Comments { get; set; }
}
我得到的名称从文本字段这样
interwierName: $("#name").text()
在这里,后端代码
public ActionResult AddComment(string name,string commentText, string interwierName)
{
var Id = db.InterwierModels
.Where(x => x.FIO == interwierName)
.Select(x => new
{
ID = x.Interwier_id
}).FirstOrDefault();
//var idForCreating = Int32.Parse(Id.ToString());
Comment cmnt = new Comment()
{
Author = name,
Comment1 = commentText,
Interview_Id = Id
};
db.Comments.Add(cmnt);
db.SaveChanges();
return Json(new { Result = "Success", Message = "Saved Successfully" });
}
但我有这个错误
严重性代码说明项目文件的线路抑制状态 错误CS0029不能类型隐式转换:“诠释”“<匿名int类型ID>”,以SmartSolutions C:\ Users \ Eugene \ Source \ Repos \ SmartWeb \ SmartSolutions \ Controllers \ InterwierController.cs 52 Active
我该如何解决它?
因为'Id'是包含命名'ID'属性的对象(未一个'int')。使用'.Select(x => x.IInterwier_id).FirstOrDefault();' –