Entity Framework – Update without Select

This post applies to EF 4.1 and above.

In a recent post I demonstrated how to delete a record from your data source without first selecting it. I’ve found this idea to be most relevant when using MVC. I don’t want a tonne of hidden fields in my form in order to get a complete entity that I can post to my controller, when all I need to delete a record is it’s primary key or id.

Entity Framework – Delete without Select

If my site has been properly developed, I may have a view model which contains only the data which my view needs. My view contains editable fields only. I don’t have a fully populated entity.

Continue reading “Entity Framework – Update without Select”

Entity Framework – Delete without Select

This post applies to EF 4.1 and above.

The following technique is applicable to updating as well. But for a more detailed explanation, head over to Entity Framework – Update without Select.

The method used to delete an entry using Entity Framework is DbContext.DbSet.Remove(Object entity), which accepts as it’s single parameter the entity you wish to delete. A subsequent call to .SaveChanges() on your context will perform a delete query on the database.

Continue reading “Entity Framework – Delete without Select”

Create a website or blog at WordPress.com

Up ↑