Slowly migrating an EDMX application to use a DbContext?

I have a legacy EF 4 library with a database-first generated ObjectContext with EntityObjects. I'd like to slowly migrate to using DbContext and am in need of some guidence.

One of the overloads for DbContext takes an existing ObjectContext. I thought this would allow me to wrap my existing ObjectContext in a DbContext and expose my existing EntityObjects through IDbSet properties. Unfortunately, when creating the DbContext, the IDbSet properties are not created and instead an exception is thrown with a message of: "Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject."

Is there no way to use a DbContext with IDbSet exposing an existing ObjectContext and EntityObjects? It seems strange that I can create a DbContext with an ObjectContext, but not expose the entities themselves.

Here's some sample code:

public class MyDbContext : DbContext
{
    public MyDbContext(MyObjectContext objectContext, bool dbContextOwnsObjectContext)
        : base(objectContext, dbContextOwnsObjectContext)
    {
    }

    public IDbSet<Person> People { get; set; }
}

The exception is caused by the DbContext trying to create the IDbSet. Person is an EntityObject from my existing EDMX.

Answers


As you noted, you cannot use the existing entity objects that the edmx created.

Have you considered using the Reverse Engineer Code First power tools?

I've used them in several projects, and its simple as pointing it at your database, it generates the model in the same project, and then removing the edmx file.


Need Your Help

jQuery Click Event Delay

javascript jquery

I have a button that triggers (1) the application of a coupon code and (2) the submission of the entire form for payment.

IF condition inside the repeater control?

c# javascript asp.net repeater

&lt;asp:CheckBox ID="chkBox1" runat="server" Text="1" /&gt;

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.