Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 906
Family Avatar asked Oct 15 '13 12:10

Family


People also ask

How do you change the code generation strategy in Entity Framework?

Re-Enable ObjectContext Code Generation Open you model in the EF Designer, right-click on a blank section of the design surface and select Properties. In the Properties window change the Code Generation Strategy from None to Default.

What is TT file in EDMX?

tt" extension indicates a T4 template file. In this case the template file is responsible for generating the classes that are represented by the Entity Model defined in your edmx file. The edmx. cs file is where the classes generated by the T4 template are put.

What is an EDMX file in asp net?

An . edmx file is an XML file that defines an Entity Data Model (EDM), describes the target database schema, and defines the mapping between the EDM and the database. An . edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.


Video Answer


2 Answers

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

like image 175
lmoglia Avatar answered Sep 25 '22 14:09

lmoglia


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

like image 27
Pawel Avatar answered Sep 24 '22 14:09

Pawel