I am looking or an ObjectContext generator for Entity Framework 5.0, not a DbContext generator. WCF Data Services requires an ObjectContext and won't work with a DbContext. If I want to use EF5 with a DataService I must provide an ObjectContext. The ObjectContext generators in Visual Studio 2010, and online are for "ADO" and for "EF 4.x". The generators for "EF 5.x" all product DbContext objects.
4 Answers
Right click the white space in the designer and select Properties, then change the Code Generation Strategy to "Default". You'll have to delete the code-first TT files, too.

- 4,906
- 23
- 18
-
1I just generated a DbContext from a DB, and the Code Generation Strategy is already Default, but it's creating a DbContext. – ProfK Dec 11 '12 at 11:53
Although too late - you will have to first delete everything under your edmx file (all the tt templates). After that you will have to download the code generator that creates ObjectContext. To do so right click in your edmx and select Add Code Generation Item. After that select Online (on the left) and select EF 5.x EntityObject Generator for C# - this is the generator that creates ObjectContext, you will see it in the description (this is also valid for EF 4.x, just find the same generator, but with 4.x in the name). Install it and you will have your model under the edmx that inherits ObjectContext.

- 1,377
- 1
- 15
- 33
using System.Data.Entity.Infrastructure;
ObjectContext context = ((IObjectContextAdapter)DbContextObject).ObjectContext;

- 10,807
- 132
- 35
- 51

- 11
- 1
You would probably want to update the version of WCF Data Services to 5.x. Then it will work with DBContext.

- 1