8.5. CRUD Operations in EF

When you utilize EF, a connection to a database called an object context is created. When new entities are created or properties change, they are not written back to the database immediately; rather, a flag is set on the entity to indicate that it has changed, but not saved to the database (a dirty state). Changes are then saved back to the database when the SaveChanges() method is called on the object context.

8.5.1. Creating

The following example shows how to create a new Film entity with a related FilmShowing entity and save the new items back to the database:

BookEntities ctx = new BookEntities(); Film NewFilm = new Film(); NewFilm.Title = "New film"; NewFilm.Description = "New film"; NewFilm.Length = 300; FilmShowing ...

Get Introducing .NET 4.0: with Visual Studio 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.