public void AddSage(Sage item) { var context = new SBContext(); context.Sages.Add(item); context.SaveChanges(); }
private void add_Click(object sender, EventArgs e) { String str = listBox1.SelectedItem.ToString(); Books book = db.Book.Where(b => b.Name == str).FirstOrDefault(); Sage sage = db.Sages.Find(id); sage.Book.Add(book); db.Entry(sage).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); UpdateListBoxes(); }