I’m trying to update a table’s foreign key after I insert record from a different form.
Table Project:
ProjectID CommentID
Table Comments:
CommentID Date Comment
First, I create the Project
and assign CommentID
a NULL
value since there is no comment yet. So far so good.
Then, in some moment, I need to add a comment to my project. I can successfully add comments, but can’t assign CommentID
in related Project
table.
This is how I’m trying to do (with no success):
MyEntities ctx = new MyEntities();
tblComents coment = new tblComments()
{
Date = DateComent.Value,
Comment = TxtComment.Text.Trim()
};
ctx.tblComments.Add(comment);
var projet = new tblProject { tblComments = comment };
ctx.SaveChanges();
Like this, I create the comment but the foreign key is never assigned in table Projects
.
Any help?
Thanks
EF6 Update Foreign Key after insert Data from another Form