We did a few things in EF 4.1 that were not at all ground-breaking or cool or anything like that, but were intended only to make programming a little bit more pleasant. One of those was making the Add and Attach methods return a reference to the added or attached entity.
A lot of stuff happens when you use a DbContext instance for the first time. Most of the time you don’t worry about this stuff, but sometimes it’s useful to know what’s happening under the hood. And even if it’s not useful, it’s hopefully interesting for its geek value alone.
(Or: How I Learned to Stop Worrying and Love CTPs)
Back in about 2001 I read Kent Beck’s Extreme Programming Explained for the first time. It changed my life as a programmer. Of course, Agile is now well-accepted and I’m always a little surprised when I encounter software journeymen* not at least trying to be Agile. But working on framework code that is used by thousands of apps can make some aspects of being Agile quite difficult.
There’s a fairly common misconception that EF4 was the fourth version of the Entity Framework. It’s a reasonable assumption to make, but actually EF4 was only the second released version of EF. It was called EF4 not because it was version 4, but because it was released as part of .NET 4.0.
You may also have heard the EF4.1 builds on top of EF4 without changing the “core” libraries. What does this mean? Read on to find out more and dazzle your friends with EF trivia.
This is one of those posts that may only be useful for a short time since we already have a group of people working on migrations support for Code First. That being said I’ve been asked twice in the corridors of Building 18 recently how to manually create the model hash that Code First stores in the EdmMetadata table so I thought a few words about that strange EdmMetadata thing might be generally useful.
Imagine your app has an entity to which changes have been made and you want to reject those changes such that they won’t be saved to the database when SaveChanges is called. Using Entity Framework 4.1 you can do this by setting the state of the entity to Unchanged. For example:
context.Entry(myEntity).State = EntityState.Unchanged;