Today I’ll show you how to create a small console application with a Step by step: Entity Framework Core and Shadow Properties example.

We’ll be modifying the code from my previous post: Step by step: .NET Core and Entity Framework Core to make the Student entity auditable without creating public/protected properties or private fields to hold the typical audit info (CreatedBy, CreatedAt, UpdatedBy and UpdatedAt) database fields.

This means that your domain entities won’t expose the audit information which almost in every case is not part of the business behavior you’ll be trying to model.

First be aware of the following prerequisites:

OS Prerequisites
Windows Windows: You must have .NET Core SDK for Windows or both Visual Studio 2015 Update 3* and .NET Core 1.0 for Visual Studio installed.
linux, mac or docker checkout .NET Core

Now let’s start:

1. Create a folder for your new project
2. Create the project
3. Create a settings file
4. Modify the project file
5. Restore packages
6. Create a marker interface in order to make your entities auditable
7. Create the Entity Framework context
8. Modify Program.cs
9. Build
10. Run

You can get the code here: https://github.com/cmendible/dotnetcore.samples/tree/master/efcore.shadowproperties.console

Hope it helps!

2 thoughts on “Step by step: Entity Framework Core and Shadow Properties

  1. Clever trick specially in cases where simple auditing is required.

    For more complicated auditing maybe a better pattern is to delegate the auditing to some Auditor bounded contex?

Leave a Reply

Your email address will not be published. Required fields are marked *