Reading Entity Framework Code First Objects from a Stored Procedure
I may be a nerd (that is, a geek who get’s paid), but I don’t enjoy writing stored procedures. However, in working with the Entity Framework, I’ve found that doing complex and often repeated queries of my Entity Framework sets is rather inefficient. My complete round-trip page loads (generate and execute query, then produce HTML) takes about 1,000ms on average. So I wanted to replace this ugly query with a simple stored procedure—precompiled, ready to fire, and highly optimized for my specific query, while still having the ability to do ad-hoc queries.
So at PDC10 I made sure to talk to the EF boys and they pointed me to the System.Data.Objects.ObjectContext.Translate method. This little bad boy will take a DataReader and create an enumerable of my objects from it—perfect.
Let’s walk through the “gotchas”. In my example below, I have a class named Product. I want to do… Read More →