tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

SaveChanges is virtual in EF4

30 Jun 2009 1 mins Entity Framework

I don’t know whether I just noticed this too late, but the SaveChanges method in upcoming EF4 is virtual. This is a great small change.

You can generate (if you’re using T4 templates for generating) your own SaveChanges method and do some work there. Well, before actions can be done using SavingChanges event, i.e. validation like in this example. But for after actions, there’s no SavedChanges event (neither in EF4). Hence adding some code into this method is very handy. For example logging actions performed is super easy.

This small change opens up new ways of thinking about SaveChanges usage.

The method also have new SaveOptions parameter. As it’s enum we can expect adding more options in future versions.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.