Entity Framework Core: History / Audit table

Some applications need to keep a list of all the changes in a table. You can implement this functionality by adding triggers in the database or by using native features of the RDBMS such as Temporal tables or Change Data Capture). Let's see how you can implement a similar functionnalities in C# with Entity Framework Core in a provider agnostic way! Note: The following code has been tested with Entity… [read more]

Entity Framework Core: Specifying data type length and precision

Note: I use the preview version of Entity Framework Core 2.0 (2.0.0-preview2-final). Things may change after the final version is released ORMs like Entity Framework Core provide great abstractions of the database. However, it should not prevent you from looking at the generated code. In this post, I want to draw attemption to the schema generation. Indeed, in a relational database, using the right… [read more]

Entity Framework Core: View the model as text

Note: I use the preview version of Entity Framework Core 2.0 (2.0.0-preview2-final). Things may change after the final version is released In the previous posts, I edited the model to change the names of the generated objects or add properties. Instead of generating the migration script to view what is generated, you can use the ToDebugString extension method to view the content of the model. using… [read more]

Entity Framework Core: Soft Delete using Query Filters

Note: I use the preview version of Entity Framework Core 2.0 (2.0.0-preview2-final). Things may change after the final version is released I continue my exploration of Entity Framework Core 2.0. Today, I'll explore how to use soft-delete (or logical delete) easily. I mean implementing soft-delete in a transparency way, e.g. as if you were actually deleting rows. To implement soft delete, you need to add a… [read more]

Entity Framework Core: Generate tracking columns

Note: I use the preview version of Entity Framework Core 2.0 (2.0.0-preview2-final). Things may change after the final version is released When you design a database, you sometimes need to add columns to track when a record changed and who made the change. To clarify, you add the following columns: CreatedAt CreatedBy LastUpdatedAt LastUpdatedBy You can easily use default values and triggers to handle the… [read more]

Entity Framework Core: Naming Convention

Note: I use the preview version of Entity Framework Core 2.0 (2.0.0-preview1-final). Things may change after the final version is released Entity Framework migration allows to generate the database schema from the model. This means the name of generated objects has to be inferred from the name of the classes and properties. The default names should be ok for lots of people. However, your DBA may ask you… [read more]