DEV Community

loading...

Discussion on: Use Action Filters to cut down your context.SaveChanges calls

Collapse
jonhilt profile image
Jon Hilton Author

Thanks Leonardo,

As to your question. Yeah that's a little tricky.

I've tended towards using GUIDs recently for this exact reason. I don't like the idea of having to round-trip to the database to get an id for an entity.

Apart from anything it makes testing harder because the database ends up being involved in something which could otherwise be tested entirely by spinning up instances of entities in memory and exercising them without ever hitting the database.

I guess a pragmatic solution is to still call SaveChanges where absolutely necessary (to generate an id for example) but try to engineer away from it where you can :-)