Archives For Code First


unicornIn 2010 I bought a Kindle and it changed my life! Since then I’ve been catching up on books I should have read years ago. Back then, reading technical books meant carrying bulky/ heavy printed books in my bag. The day I got my first kindle, is the day I started reading again!

Since then, I read quite a few books! Below are some of the books that helped me love and master Entity Framework!

Before you go through this list of books, I have to admit that I have a huge preference for Entity Framework Code First (aka. Magic Unicorn) because I find it easy to work with. It is easier to maintain, to evolve and it allows you to use true Plain Old CLR Objects (POCOs). If you have any suggestions for good Entity Framework, please share them through this post’s comments.

Continue Reading…


When observing Query Plans through the Windows Azure Management Portal for SQL Database you may come across warnings. Some warning are about missing Indexes and some are about performance issues related to the Query itself.

2013-02-11_17h22_09

This specific warning occurs when you are comparing two strings that are not of the same Type. By this I mean one is NVARCHAR and the second is VARCHAR.

Addressing these warnings will have a great impact on query performance with large datasets. It may not be noticeable on tables that have a small amount of records. Once you start querying over a few million records, performance gains will be noticeable by the end users.

Fixing these issues can go a long way when it comes to end user satisfaction! Remember, slow applications are applications to which people find alternatives!

Continue Reading…


There are times when entities don’t need navigation properties on both sides of the relationship. This is an example you can use to map to an existing database or generate a brand new database on Windows Azure SQL Database.

2013-02-09_18h15_08

The ERD shows a Many to Many relationship between the FlightLog and the Airport entities. The requirements for the current model has no need for Airport to have a Navigation Property of FlightLogs.

Using Entity Frame Work Code First, the following statement can be used in the EntityTypeConfiguration to configure the relationship.

HasMany(r => r.Airports)
    .WithMany() // No navigation property here
    .Map(m =>
        {
            m.MapLeftKey("FlightLogId");
            m.MapRightKey("AirportId");
            m.ToTable("BridgeTableForAirportsAndFlightlogs");
        });

FlightLog has many Airports, the relationship is held in an intermediate table called BridgeTableForAirportsAndFlightlogs. By not specifying a property for the inverse Navigation Property, a unidirectional Many to Many relationship is created.

Continue Reading…


Query encapsulation can become quite empowering. For instance, query objects can be decorated, extended and reused. They allow us to implement concepts like targeted caching or user defined queries. They even allow us to execute the same query on two different data sources.

In part 2 of this series, we will be looking at how we can leverage the IModelQuery interface to enable us to reuse queries. Continue Reading…