How to access navigation property of deleted entity

In this post I am going to show you a small Entity Framework code first trick. When you remove an entity from the context its state is set to Deleted and all its navigation properties are nulled. This is done by DbContext internally. However you might want to know what was the related entities (navigation properties) before the entity was deleted. For instance you want to create some audit logs of deleted entity. I will show you how to do it with minimal effort.

By Mirek on (tags: Code First, Entity Framework, navigation property, categories: code)

Sql Server application roles with Entity Framework Code First Migrations

A time ago I have been writing about the Sql Server application roles, what are the benefits of using them and what are the limitations when we want to incorporate the Entity Framework to use application role. Today I will show you how to workaround those limitations with new Entity Framework facility introduced in version 6 of the framework.

By Mirek on (tags: Application Role, Entity Framework, SQL Server, categories: architecture, code)