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

2

8

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.

Gabar answered 23/11, 2012 at 14:18 Comment(3)
Do I have an answer that satisfies you?Babble
Are you using Visual studio 2010? Do you see any files named *.context.tt and *.tt added in your project?Farver
Do you have a Primary Key in your DB? If not, this can be an issue.Pennell
B
8

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.
Babble answered 31/12, 2013 at 6:37 Comment(4)
EDMX is going away FYI in EF Core 1.0 ( NEW names are asp.net Core 1 , and it is EF Core 1 instead of EF7 ) hanselman.com/blog/…Babble
By now (VS 2015) it's called "Code Generation Strategy: Legacy ObjectContext".Impuissant
good to know. thx. I have to sometimes open up projects with EDMX, it is really quite awful ( regenerating files ) various spatial issues on some developers machines which requires a runtime to be installed. It might be the edmx version that was implemented as I didn't see so many problems many years ago. but i don't trust it. I will use code first, but honestly i'm starting to use Dapper recentlyBabble
Ran into too many issues with Dapper - IQueryable etc... so back to EF with pocos etc...Babble
B
2

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

Braley answered 25/1, 2018 at 11:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.