Hi I have a problem saving 2 tables of my database at the same time but my first table saves without a problem alone. The second table is related to the first table and has FK already. Please help..here is my code. Thanks
//Save to Database
//1st Table
casecrawlerdbEntities1 db = new casecrawlerdbEntities1();
document document = new document();
document.DocumentNo = DocumentNo;
document.Description = Description;
document.Author = Author;
document.PublishedDate = DateTime.Parse(PublishedDate); ;
document.Summary = Summary;
document.SearchKeys = richTextBox9.ToString();
document.References = url;
document.IsPublic = false;
document.IsPublished = false;
document.CreatedDate = DateTime.Now;
db.documents.AddObject(document);
db.SaveChanges();
//2nd Table
content content = new content();
content.ContentType = ContentType;
content.Content = Content;
db.contents.AddObject(content);
db.SaveChanges();
MessageBox.Show("Saved to Database");
Before calling
db.contents.AddObject(content);, do:(assuming that this is how the relation to the Document is named).
Also, you may try calling
db.SaveChanges();only once (after the contents is created).