Jon Galloway and I recently documented what we were learning about Entity Framework Code-First and oData as part of the Full Stack project. It turns out, however, that we were into some bleeding edge technology, and while everything we posted works, it works read-only, as written it is not possible to update the data. Not great.
With the guidance of Chris “Woody” Woodruff we stopped using batch updating and we opened up our error messages to see more detail. This led Jon to an article by Rowan Miller which targeted exactly the problem we were having. Jon documents it all here.
Key was that we were using DbContext, which is a wonderfully lightweight convention-over-configuration based wrapper over ObjectContext, but one of its limitations is that it does not does not include IUpdatable support, as documented here.
The answer, as documented in detail by Jon and written up in even more detail by Rowan is to expose the ObjectContext which you can do directly from the DbContext.
public class PersonTestDataService : DataService<ObjectContext> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } protected override ObjectContext CreateDataSource() { var ctx = new PersonContext(); var objectContext = ((IObjectContextAdapter)ctx).ObjectContext; objectContext.ContextOptions.ProxyCreationEnabled = false; return objectContext; } }
With this done, you must remember to update the client proxy using DataSvcUtil.exe as explained in the earlier article.
Be sure to read Jon’s article on all of this.