Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4.1 auto generate with DbContext when creating ADO.NET Entity Data Model

I would like to work with DbContext instead of ObjectContext. I updated EF so now I have the DbContext, but I want to generate my strongly-typed context based on the DbContext and not the ObjectContext. When I add new ADO.NET Entity Data Model, it is still based on the ObjectContext. Is it not possible to have it base off of DbContext in Visual Studio 2010 with EF 4.1?

UPDATE:

Okay, I followed the directions in this link and was able to generate the DbContext template objects. However, now it is saying there is ambiguity between the template entities and the entities in my .edmx file. How do I resovle this? Do I blow away the ones in the .edmx file?

like image 598
lintmouse Avatar asked Sep 08 '12 14:09

lintmouse


People also ask

Can we use Entity Framework and ADO.NET together?

EF is built on top of ADO.Net, meaning that you can use both at the same time.

How do I add ado net entity data model?

Adding an Entity Data Model To add an Entity Data Model to your solution, do the following: In the Solution Explorer, right-click your application and select Add and then New Item. From Visual Studio installed templates, select ADO.NET Entity Data Model (see the figure that follows). Click Add.

How do you create a model and context class from an existing database?

To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add. This will open the Entity Data Model wizard as shown below.


1 Answers

Okay, I got this to work by right-clicking in the .edmx diagram view and selecting 'Add Code Generation Item...' and then selecting 'EF 4.x DbContext Generator' from the options. It worked perfectly.

like image 142
lintmouse Avatar answered Nov 15 '22 04:11

lintmouse