Task list

Image

In this chapter we’ll (finally!) start working with actual data.

Crud operations

Image

If  you know how to program in .NET (and you do, or you wouldn’t have made it this far in the book), you know how to perform basic CRUD operations using your Entity Framework model. The only thing that’s (more or less) unique is calling SaveChanges() to persist the changes to the database. But there’s no reason for you to take my word on that, so we’ll start with a quick look at CRUD operations in the Entity Framework.

Entity state

Image

In order for the Entity Framework to work its magic when you call SaveChanges(), it has to keep track of what has to be saved. After we’ve examined the changes that can be made, we’ll take a peek behind the curtain and explore the change-tracking objects that manage that and how you can take control of them. This is pretty advanced stuff, but we will look at one common operation using entity state entries: the ability to roll back changes to an entity.

Dbcontext validation

Image

Remember that old saw about “garbage in, garbage out”? Well of course you need to make sure the data that SaveChanges() is persisting is, if not correct, at least valid. At the end of the chapter we’ll look at how .NET validation works with Entity Framework and the extensions the DbContext API adds to integrate with the .NET Validation API.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset