草庐IT

questionComment

全部标签

c# - 将新实体插入到具有标识主键的上下文中

我想在我的SQL表中插入一条新记录。我试过:publicvoidCreateComment(intquestionId,stringcomment){QuestionCommentquestionComment=context.TableName.Create();//1*questionComment.propertyThatIsNotAConstraint=questionId;questionComment.body=comment;context.QuestionComments.Add(questionComment);context.SaveChanges();//ERRO

c# - 将新实体插入到具有标识主键的上下文中

我想在我的SQL表中插入一条新记录。我试过:publicvoidCreateComment(intquestionId,stringcomment){QuestionCommentquestionComment=context.TableName.Create();//1*questionComment.propertyThatIsNotAConstraint=questionId;questionComment.body=comment;context.QuestionComments.Add(questionComment);context.SaveChanges();//ERRO