efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Support partial entity materialization

Open dmlsrc opened this issue 11 years ago • 1 comments

Hi,

One thing that has always driven me mad about EF was the inefficiency of a trivial update of a single column on a large record. Has this been improved in EF7?

Take for example a blog post being stored in a single table, it has the actual HTML content in one column, a visibility flag in another, and a PK column.

To update an existing post and make it not visible, EF will pull the entire post with HTML across the wire and into memory, let me update the visibility flag, and then once again pull the entire record from the database. This is nuts.

When we resort to writing spaghetti to trick EF into updating a single column we are met with DbEntityValidationException exceptions when we fail to provide values for required fields that will not be pushed to SQL anyway. Then our only option is to resort to putting junk into the required fields (also makes it impossible to use AutoMapper), which results in even hairier code as demonstrated here: http://stackoverflow.com/a/24810217

Let me create a new DTO with the PK and possibly a rowversion that I looked up via projection and the single column I want to modify. Monitor which properties have been touched. And push the touched ones down to SQL as an update statement, ignoring validation for anything that has not been touched. Don't select anything unless asked.

I am glad that you guys are finally looking into implementing disconnected graph support, which was a major pain point in one of my past projects. Efficient partial update support is my second concern when I use EF in a project. There are some on my team that swear by Dapper.Net due to this kind of nonsense.

Thanks, ltctech

dmlsrc avatar Aug 15 '15 01:08 dmlsrc

Dupe of https://github.com/aspnet/EntityFrameworkCore/issues/1387?

AndriySvyryd avatar Aug 30 '17 06:08 AndriySvyryd