code

How to access navigation property of deleted entity

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

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.

architecture

Sql Server application roles with Entity Framework Code First Migrations

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

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.

architecture

Using SQL FileTable in Entity Framework

By Mirek on (tags: Entity Framework, FILESTREAM, FILETABLE, SQL, categories: architecture, infrastructure, code)

FileTable is a great new feature in SQL Server 2012 which facilitates storing and working with unstructured blob data in SQL Server. Unfortunately is not yet supported in Entity Framework, so you cannot simply use FileTable in your entity model. But there is a workaround for this inconvenience, which I am going to show you in this post.

architecture

Entity Framework – lazy loading properties

By Mirek on (tags: Entity Framework, lazy loading, shared primary key associations, table splitting, categories: architecture, code)

In the Entity Framework we can easily enable lazy loading of navigation properties by marking them as virtual. This however applies only to properties that reference other related entity type. The framework does not support lazy loading of scalar or primitive properties. But there is a trick to fill this lack quite easily.