Switching from ObjectContext to DbContext in your Entity Framework EDMX File


Tres easy and much cleaner classes turfed out the other end;

http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx

  1. #1 by Gareth on March 22, 2012 - 11:01

    Code first is alot easier to maintain that the wizard. Definitely when you want to extend the model. Remember though if you change your model (adding new fields), you will need to drop and re-create the DB to include the code to seed your existing data.

    Also the TDD for seeding and testing your models is nice…….

  2. #2 by Shawson on May 1, 2012 - 22:04

    Code-first is dirty! This is db first, but using the DbCOntext as the context (normally native to code first) as opposed to the default ObjectContext. To update your model you go to the edmx, right click the design surface and say update model! What could be simpler?! But on the flip side, because I’m using DbContext with the t4 templates, I have access to how the classes get generated and can easily inspect them (and the context object itself). Very nice way of working.

(will not be published)