Updating & deleting entities

There really isn’t very much for me to say about updating and editing entities. Changing a property is changing a property. As for deleting? Well, you need to call a different method depending on which API you’re using (ObjectContext.DeleteObject() or DbSet<T>.Remove()), and I’ve already told you that the entities aren’t actually deleted until after the database is updated by a call to SaveChanges().

But there is one thig we haven’t discussed: What happens to an entity when an entity it is related to is removed from the database? Let’s look at how that works:

It all depends on the nullability of the foreign key. That determines whether the relationship is optional or required. If the foreign key can be null, the relationship ...

Get Fluent Entity Framework 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.