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 creat…

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

Concurrency handling in Entity Framework

In this post I am going to present my solution for handling optimistic concurrency scenarios in Entity Framework. This solution is somehow an extension of recommended approaches presented on MSDN Entity Framework learning  center here. Apart from pessimistic concurrency pattern, which assumes creating read or update locks on data when it is edited, this approach concerns o…

By Mirek on (tags: database concurrency, Entity Framework, 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. I am specifically talking about dat…

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

Mapping XML column with XSD schema validation in EF Code First

The XML data type allows storing a xml content in our SQL Server database. The great feature is that we can also attach an XSD schema to it and have the xml content automatically validated. Here I am going to show you how to set it up together with Entity Framework Code First. Storing XSD Schema in database and mapping entity One could ask: what is the point of validating the x…

By Mirek on (tags: Entity Framework, SQL Server, XML, XSD, categories: architecture, code)

InitialCreate migration and why is it important

Entity Framework migrations is indeed a great feature. It makes you don’t need to worry about the database schema updates almost at all. There are however few things you must know to properly understand and use EF migrations. This post describes few of those things. Usually when you start a new project which makes use of Entity Framework and you starts developing it with a defa…

By Mirek on (tags: Entity Framework, migrations, categories: architecture, tools, code)

SQL Server Application Role

Sql Server Application Role is a way to control access to the database for specific applications. It simply grants a access to a program  that provides application role credentials, not for the user login that is used to connect to a database. Application Roles are useful when you want to restrict direct access to the database for a user or group of users, but you want the…

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

Mock your database with no effort

This is a tool I was looking for for a very long time. The Effort is a library that allows you to mock your database with basically no effort. This is simply a database provider for Entity Framework which uses an in memory database (NMemory). Although it is still in beta version it is fully functional for most cases. I found it very usefull in unit and functional testing. Ok so…

By Mirek on (tags: Effort, Entity Framework, testing, categories: tools)

FileTable performance test

In my last post I have described a workaround for using a FileTable in Entity Framework 6.0. In this post I would like to show you the results of performance test of storing big documents in sql FileTable. I have put in comparison storing 10 pdf documents 16MB each in database. First application is a Entity Framework Code First based app with mapped stored procedures. Those pro…

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

Using SQL FileTable in Entity Framework

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. FileTable is a fixed schema regular sql t…

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

Entity Framework – lazy loading properties

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. Let’s assume we would like to lazy load some properties…

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