Code First: Building a Cleaner Model with Entity Framework

Code First is a new approach to building your model in Entity Framework 4 that allows you to create your domain model with plain .NET classes that are completely under your control. Previously in Entity Framework you were required to build your model with an EDMX file that forced your model to be expressed in a visual designer. While this approach works in some situations, it can get in the way of your development work-flow and can create extra baggage developers don’t need.

Code First relies on a set of conventions that handle connection strings, mapping to your storage solution, defining primary keys, finding relationships between classes and more. Of course all of these conventions can be overridden in code as well, which gives you plenty of flexibility.

In this talk I’ll describe and demonstrate the core features of Code First so you can make an informed decision as to its usefulness in your development environment.

Bio: Chris Sutton is a software developer and technical trainer in Eastern Iowa. He is organizing a .NET user group in Iowa City and he co-founded the Iowa Code Camp in 2008. Chris is a Microsoft MVP, a Microsoft Certified Trainer (MCT) and holds the MCPD:Enterprise certification. He has been consulting and speaking on web related topics since 2005, and he has 11 years of professional software development experience and loves developing for the web. He also enjoys hiking and biking in the summer and snowshoeing in the winter.

If you plan on making our meeting on May 7th, please RSVP.

This entry was posted in Meetings. Bookmark the permalink.

6 Responses to Code First: Building a Cleaner Model with Entity Framework

  1. Roman says:

    This is a tangent, but I would like to know if you have found a solution to mixing stored procedure entity updates and entity framework updates. Example: a stored proc sp_update_total_cost takes an order_id , updates the totalCost value. EF knows nothing about this update because it happened DB side — until you refresh the context. Do you know of a workaround or solution that does not require a context refresh?
    Thanks! Looking forward to your talk!

  2. Roman says:

    Here is a link to importing from an existing DB whilst using Code First:

  3. Roman says:

    And just in case someone was wondering about my first comment — the answer is the context.Refresh() function. Like so context.SaveChanges(); context.Refresh(option, entityToRefresh);

  4. Chris Missal says:

    Thanks Roman! I can see this being very helpful for me for an upcoming project. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *