Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

empty .Designer.cs file after generating .edmx using EF 4.x on ASP.Net MVC4 application

I have started a very simple ASP.Net MVC4 applictaion with a Database first approach (with existing DB). I have generated .edmx using ADO.Net Entity Data Model template. The process has created a xxxxxxx.Designer.cs file under xxxxxxx.edmx option. However, the .cs file is empty with the following message.

// Default code generation is disabled for model 'C:\Visual Studio 2010\Projects\xxx\DProject\Models\BIReportDataModel.edmx'. 
// To enable default code generation, change the value of the 'Code Generation Strategy' designer
// property to an alternate value. This property is available in the Properties Window when the model is
// open in the designer.

Following the message I have changed the properties which generated code in the xxxxxxx.Designer.cs file.

Question:

  1. Is this the correct thing to do? What is the purpose of this file?
  2. Do I also need to generate Strongly-typed DBContext classes from the .edmx designer page by right clicking "add code generation item" and then selecting EF DBContext Generator?

What exactly is the process for Database first approach?

I have seen lots of post/blogs/tutorials and all seems to be very confusing and mostly for CodeFirst approach.

like image 783
PineCone Avatar asked Nov 23 '12 14:11

PineCone


2 Answers

Code First is technically BOTH a Database first and NOT having a database (it is flexible) You simply create POCO's ( plain old C# objects) These classes will map out your database table schema structure how you want, whether the database exist or not. If you don't know what you are doing then you probably don't want to do this.

EDMX, previously was that the designer would get populated, but in VS 2012 and greater tt files are the default. You should use a tt editor from nuget to really get much out of them.

OR I suggest you do the following

 1. Open the EDMX file - double click
 2. Right Click in the EDMX diagram and click on Properties 
 3. In the properties window change the "Code Generation Strategy" from  None to Default
 4. Delte the tt files as you don't want both entities / contexts in project.
like image 118
Tom Stickel Avatar answered Sep 23 '22 01:09

Tom Stickel


In visual studio 2017 , to create code in designer .cs file (using entity framework 5.0) i do:

  • Open model .edmx and change "code generation strategy"
  • Delete .tt files in model

enter image description here

like image 1
vitalinvent Avatar answered Sep 21 '22 01:09

vitalinvent