Family
Family

Reputation: 1113

Change EF 6 Code Generation Strategy from T4

In the past I have successfully created edmx files. This was using EF5 and Visual Studio 2012. I have since upgraded to Visual Studio 2013 and EF6. The existing EF 5 code still works, but now I have a problem. I can create edmx files, and an EntityDataSource, I can configure the data source, it sees the tables and columns fine, but when I try to refresh the schema I get:

The schema could not be determined because of the following error from the EntityDataSource:

Could not find the CLR type for (my type here)

I have seen a solution on-line telling me to change my Code Generation Strategy to default (the existing edmx files created in EF 5 are set as Legacy ObjectContext), but it won't let me do this because the option 'T4' is grayed out.

enter image description here

Is there a way I can force the Code Generation Strategy to not use T4?

EDIT:

Pawel states that EntityDataSource does not support EF 6. Is there a tutorial available that shows an easy step-by-step guide of how to connect to EF 6? I have got all my EF information from the book Beginning ASP.Net 4, but it is now obviously out-dated. I see that EF 6 is still in beta stage. Maybe they'll add support for EntityDataSource at some stage?

EDIT 2:

OK, I've been fiddling around with this for a bit, and I can connect using LinqDataSource. I won't get a chance to play around with it much for a few days, but it looks like this works.

EDIT 3:

Using LinqDataSource doesn't work. The only CRUD operation it can perform is Read. Obviously there must be a way to use the new EF 6.0 framework (Pawel has suggested I use MVC), but they couldn't have broken it completely for my scenario (using web site), could they?

EDIT 4:

I have found a solution for my scenario, see my answer below.

Upvotes: 18

Views: 31265

Answers (6)

Jaiyaram Mahendran
Jaiyaram Mahendran

Reputation: 17

I am using visual studio 2015

  1. Dbl click the xxx.edmx file in the solution explorer, this should open the diagarm in the designer,

  2. press alt+enter which opens the property window

  3. Look for "Code Generation Strategy" property - choose the value T4 from the drop down to Legacy Object Content.

Upvotes: 0

lmoglia
lmoglia

Reputation: 524

i already have VS2013 Community, and i was fighting with the same problem. Just like your image, the code generation strategy was disabled, i mean, it wasn't possible to change, but... right click on the property name "Code Generation Strategy" then just click 'Reset' and the property value will change to Legacy ObjectContext!

I hope that it can help someone!

PD:Sorry, my english is aweful! xP

Upvotes: 14

Amarjit Singh Virkh
Amarjit Singh Virkh

Reputation: 41

In Ef6 you can use legacy context. Just right click the edmx file and in open with option open it in XML viewer. Then search for legacy and set the value of it as true.

Upvotes: 4

Pawel
Pawel

Reputation: 31610

Due to changes in EF6 if you are using EF6 in VS2012/VS2013 the only supported generation strategy is T4. You can get EntityObject based entities and ObjectContext based context by using T4 templates from VS Gallery. Note: EntityDataSource does not currently support EF6.

EDIT

The preview of the EntityDataSourceControl with EF6 support is now available

Upvotes: 12

ransems
ransems

Reputation: 671

I have the same issue and (EF6) and when I changed the Metadata Artifact Processing to "Copy to Output Directory" I still get the same error. Which has been suggested as a solution to most of my problems.

My steps (to reproduce error):

Create a directory called DAL, add edmx file, allow it to create connection string, add two tables, build.

Create a default.aspx page, drag the EntityDataSource from toolbox, click the flyout Configure DataSource, choose my named Connection from above, and I get the error:

The metatdata specified in the connection string could not be loaded. Consider rebuilding the web project to build assemblies that may contain metadata. The following error(s) occurred: The provider did not return a ProviderManifest instance.

Been trying to find a solution for about 24h now.

So now when I choose EF5 (not 6) and I do steps above I right click on the Diagram Surface and go to properties I change two setting:

1.) Artifact Processing to "Copy to Output Directory" 2.) Change the Code Generation Strategies to "Legacy ObjectContext" from T4

Which allows me to drag the EntityDataSource from the toolbox, click the flyout Configure DataSource, choose my named Connection from above and everything is back to world of love an programming...

Only took me 24 solid hours and 2 wasted days of coding to finally piece together a suitable solution. And my laptop got flatten and reinstalled, b/c I was soooo desperate and pulling my hair out.

Upvotes: 0

Family
Family

Reputation: 1113

As Pawel mentions you can only use T4 in EF 6. What I did to get my system back to using EF 5 was to uninstall EF 6, using the NuGet package manager (Website -> Manage NuGet Packages -> Installed Packages -> EntityFramework -> Uninstall). Then I had to add EF 5 using NuGet package manager (same menu but Online instead of Installed Packages). Then I had to remove the following from web.config:

<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

Now when I add an ADO.NET Entity Data Model it asks me what version of Entity Framework I want to use, but Entity Framework 6.0 is grayed out. This is obviously a bug, it should ask this when EF 6.0 is installed, not when it isn't. When it was installed it never asked what version I wanted and just automatically created an edmx for version 6.0

Upvotes: 1

Related Questions