Entity Framework Code-First is the coolest thing since sliced bread, Windows Phone is the hottest thing since Tickle-Me-Elmo and oData is just too great to ignore.
As part of the Full Stack project, we wanted to put them together, which turns out to be pretty easy… once you know how.
EF Code-First CTP5 is available now and there should be very few breaking changes in the release edition, which is due early in 2011.
Note: EF Code-First evolved rapidly and many of the existing documents and blog posts which were written with earlier versions, may now be obsolete or at least misleading. |
Code-First?
With traditional Entity Framework you start with a database and from that you generate “entities” – classes that bridge between the relational database and your object oriented program.

With Code-First (Magic-Unicorn) (see Hanselman’s write up and this later write up by Scott Guthrie) the Entity Framework looks at classes you created and says “if I had created these classes, the database would have to have looked like this…” and creates the database for you! By deriving your entity collections from DbSet and exposing them via a class that derives from DbContext, you “turn on” database backing for your POCO with a minimum of code and no hidden designer or configuration files.
POCO == Plain Old CLR Objects |
Your entity objects can be used throughout your applications – in web applications, console applications, Silverlight and Windows Phone applications, etc. In our case, we’ll want to read and update data from a Windows Phone client application, so we’ll expose the entities through a DataService and hook the Windows Phone client application to that data via proxies. Piece of Pie. Easy as cake.
Continue reading →