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)

Localized enums with Entity Framework Code-First 4.1 in WPF MVVM and ASP.NET MVC 3. Part 3)

Part 3. Displaying and binding localized names of enum values in ASP.NET MVC 3 application To display localized enums in ASP.NET MVC 3 application we use custom description attribute described in Part 2) and extension method to get the description for each enum value. The type converter is not useful here so we need another approach to achieve the goal. Let’s generate the editi…

By Mirek on (tags: ASP.NET MVC, Code First, Entity Framework, enums, lozalization, mvvm, WPF, categories: code)

Localized enums with Entity Framework Code-First 4.1 in WPF MVVM and ASP.NET MVC 3. Part 2)

  Part 2. Displaying localized names of enum values in WPF application To achieve the human readable enums I have performed following steps. For each language I want to support I have added a resource (.resx) file with key equals the string representation of the enum value.   Then we decorate our enum values with Display attribute as follows 1: public enum Status 2: {…

By Mirek on (tags: ASP.NET MVC, Code First, Entity Framework, enums, localization, mvvm, WPF, categories: code)

Localized enums with Entity Framework Code-First 4.1 in WPF MVVM and ASP.NET MVC 3

In part 1) I would like to present the solution of using enum types with Entity Framework Code-First (EF CF later). Then in part 2) I would like to show how easily display these enums in WPF MVVM and in Part 3)  I will try to explain my approach for displaying and binding localized enums in ASP.NET MVC 3 application. EF CF approach is still developed and in version 4.1 it …

By Mirek on (tags: ASP.NET MVC, Code First, Entity Framework, enums, localization, mvvm, WPF, categories: code, web)

EF Code First and SqlServer Ce 4.0 – the simplest example ever.

Recently I needed to write a simple database application. I chose the Entity Framework Code First (Code Only) as a Object Relational Mapper (ORM) because its simplicity and quick development process. If you did not yet heard about EF Code First then this is a good place to start. Entity framework is a very powerful technology. It totally makes the whole dirty work which in the …

By Mirek on (tags: Code First, Entity Framework, SqlServer Ce 4.0, categories: code)