CreatedAt property with Entity framework


You’re building a new application, and you’re using Entity Framework Code First. Probably all your entities need an Id and CreatedAt/UpdatedAt property.

The sample below shows you how to define these properties in a base class, and (more importantly) how to set them correctly on every save, without setting them manually on every place where you’re changing things.

We do this by overriding the SaveChanges method of the DbContext.

I hope you like my sample, so please let me know below or share this post on social media.

About the author

Stephan van Rooij

Add comment

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.

Recent posts