我是实体框架的新手,现在正在努力解决问题。我正在使用MVC api和EF6。
我在PUT方法中保存了成员详细信息。这工作得很好。
现在,我修改了代码以保存注释(添加新方法PublishComment()),但这会破坏代码而不会出现任何错误消息!调试会话只挂在db.SaveChanges()。
上public void Put(Guid id, MemberListItem item)
{
using (Context db = new Context())
{
Person updPerson = db.People.Find(item.PersonID);
if (updPerson.PrincipleContact != item.PrincipalMember)
{
updPerson.PrincipleContact = item.PrincipalMember;
}
string memberName = updPerson.GivenName1;
Guid memberID = updPerson.MemberID;
db.Entry(updPerson).State = System.Data.Entity.EntityState.Modified;
PublishComment(db, memberID, "User Modified. " + memberName + " modified from user profile.");
db.SaveChanges();
}
public void PublishComment(Context db, Guid memberID, string comment)
{
MemberComment newComment = new MemberComment();
newComment.CommentID = new Guid();
newComment.MemberID = memberID;
newComment.DateAdded = DateTime.Now;
newComment.Comment = DateTime.Now.ToShortDateString() +": " + comment;
db.MemberComments.Add(newComment);
}
答案 0 :(得分:1)