0

Possible Duplicate:
Issue with updating database entity

I am working on the relational database with Entity FrameWork - 4.0. I am totally new for Entity FrameWork. I have 3 tables in my database with following relations :

         1   to   many       1   to  many
Ceremony -------------> Menu ------------> CourseOption

The problem is while updating the existing ceremony in the database. Suppose the Ceremony which i am going to update contains 1 menu and 1 courseoption. If i change the existing Menu and CourseOption property value than it works fine. Changes take place to the database correctly to the database.

Main Problem -> But if i add new Menu and CourseOption Or delete existing Menu and CourseOption than there will be no effect to database for this change.

C# code to update entry in the database :

db.Entry(ceremony).State = EntityState.Modified;

What i am missing ?

Community
  • 1
  • 1
Tom Rider
  • 2,747
  • 7
  • 42
  • 65

1 Answers1

0

For adding we have to write code like

db.Entry.Add(ceremony);
db.SaveChanges();

For Deleting We have to write like

db.Entry(ceremony).State = EntityState.Deleted;  
Pavan Kumar
  • 190
  • 2
  • 8