I want to add a new book to my database, but it doesn't work.
class Program
{
static void Main(string[] args)
{
Knigi_DataEntities entities = new Knigi_DataEntities();
Books newBook = new Books();
newBook.Name = "C# 4 How-to";
newBook.Published = 2010;
newBook.Book_ID = 4;
entities.AddToBooks(newBook);
entities.SaveChanges();
Knigi_DataEntities ent = new Knigi_DataEntities();
foreach (var book in ent.Books)
{
Console.WriteLine("{0}, {1} {2} ",
book.Book_ID, book.Name, book.Published);
}
}
}
but when I close //entities.SaveChanges();
, the console displays objects that are already in my database. Therefore problems are caused by entities.SaveChanges();
Please tell me, how to add new objects?