sanmis
sanmis

Reputation: 525

code generation strategy to "default" in visual studio 2013

How can I change code generation strategy to "Default" while creating ADO.net entity model class? When .edmx file is generated, it contains .tt files. I deleted those and want to regenerate using default code generation strategy. I was able to do this in Visual Studio 2012 but can't do this anymore in Visual Studio 2013. Code generation strategy is set to T4 and I can't regenerate the files. Any help?

Upvotes: 5

Views: 1306

Answers (2)

Manish Nayak
Manish Nayak

Reputation: 665

I was facing an issue while changing code generation strategy to “default” in visual studio 2013. After four to five hours of research, I found this solution.

  1. As you told in question, delete two .tt files from edmx.

enter image description here

  1. Open edmx designer, right click on the blank surface and choose properties from the context menu.

enter image description here

  1. As you can see there is no drop down list selection to choose Code Generation Strategy. By default, T4 is selected and it is disabled also. For your information, T4 is a replacement of "None" option of Visual Studio 2012 and the Legacy ObjectContext is a replacement of "Default" option of Visual Studio 2012. Now to set T4 to Legacy ObjectContext, right click on Code Generation Strategy option. You will see the "reset" option in the context menu, click on it.

enter image description here

The Legacy ObjectContext is set now

enter image description here

  1. The setup is not complete yet. You have to add two references to work this completely.
    • System.Data.Entity
    • System.Data.Entity.Design

To add these two references, right click on References folder and click on Add Reference. Now type "System.Data.Entity" in the search box, you will see these two references in the list. Select these references and click on OK button.

enter image description here

Hope this will work for everyone, Thanks.

Upvotes: 0

Sara Nikta Yousefi
Sara Nikta Yousefi

Reputation: 1607

I'm working with asp.net webform so I'm not sure my answer would be helpful to u or not...However This is my solution...

1.remove the last edmx file.

2.remove the last connection string.

3.add ado.net entity model again and set options like before.

4.DO NOT remove .tt files and DO NOT try to change code strategy generation.

5.rebuild solution.

6.I believe now you would see a lot of errors about AddObject and DeleteObject...Just change This two to Add and Remove (note that for deleteObject you may not have had to write table name before but for remove you should do that).

for example: db.News.AddObject(N); changes to db.News.Add(N); and db.News.DeleteObject(N); changes to db.News.Remove(N); and db.DeleteObject(N); changes to db.News.Remove(N);

Upvotes: 2

Related Questions