0

i am continously get exception in dbContext save changes line? my data enters through sql 2012 but not from visual studio? anyone can help me how can i handle or remove this exception?

try
{
    using (entity = new ShelfEntities())
    {
        bookTable book = new bookTable();

        book.BookName = textBookName.Text;
        book.BookAuthor = textBookAuthor.Text;
        book.BookPrice = Convert.ToInt32(textBookPrice.Text);

        entity.bookTables.Add(book);
        entity.SaveChanges();

        MessageBox.Show("successfull");
        listBook.Items.Clear();
        listBook.Items.AddRange(entity.bookTables.Select(x => x.BookName).ToArray());
    }
}
catch (Exception y)
{
    MessageBox.Show("" + y);
}
Sjon
  • 4,989
  • 6
  • 28
  • 46
  • wich exception did you got? – timguy Feb 24 '20 at 13:40
  • @timguy System.Data.Entity.Infrasructure.DbUpdateExcpetion: Unable to update Entity set ‘book’ because it has a defining query and no elements exists in the elements to support the current operaion – Yahya Khwaja Feb 26 '20 at 10:32

1 Answers1

0

I just googled you exception. This is what you should do first:

So check for this: Unable to update the EntitySet - because it has a DefiningQuery and no <UpdateFunction> element exist

It usually happens because one of the following reasons:

Entity Set is mapped from Database view
A custom Database query
Database table doesn't have a primary key

After doing so, you may still need to update in the Entity Framework designer (or alternatively delete the entity and then add it) before you stop getting the error.

timguy
  • 2,063
  • 2
  • 21
  • 40