Get DBContext from ObjectContext
Asked Answered
E

1

11

I'm using the latest versions of ASP.NET MVC, SQL Server, and Entity Framework. I am not using code first.

I can easily create an object context using the class generated by my EDMX file.

But is there any way to obtain a DBContext object from that class? I would like to use its extended features.

Endomorphism answered 27/1, 2013 at 22:48 Comment(0)
K
23

You can add a code generation item for a DbContext. Right-click on the design surface of the edmx and choose "Add code generation item" and select DbContext Generator from the Add New Item dialog (you may have to look in online templates). This will create a t4 template that generates a DbContext.

If you want to keep working with the ObjectContext API, but sometimes want to switch to DbContext you can create a DbContext with the constructor accepting an ObjectContext as parameter.

Kostival answered 27/1, 2013 at 23:13 Comment(1)
Either option would be just what I was looking for. Thanks.Endomorphism

© 2022 - 2024 — McMap. All rights reserved.