Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 在ASP.Net MVC4应用程序上使用EF 4.x生成.edmx后,清空.Designer.cs文件_Entity Framework_Asp.net Mvc 4_Ef Database First - Fatal编程技术网

Entity framework 在ASP.Net MVC4应用程序上使用EF 4.x生成.edmx后,清空.Designer.cs文件

Entity framework 在ASP.Net MVC4应用程序上使用EF 4.x生成.edmx后,清空.Designer.cs文件,entity-framework,asp.net-mvc-4,ef-database-first,Entity Framework,Asp.net Mvc 4,Ef Database First,我使用数据库优先的方法(使用现有数据库)启动了一个非常简单的ASP.NETMVC4应用程序。我已经使用ADO.Net实体数据模型模板生成了.edmx。该过程已在xxxxxxx.edmx选项下创建了一个xxxxxxx.Designer.cs文件。但是,.cs文件为空,并显示以下消息 // Default code generation is disabled for model 'C:\Visual Studio 2010\Projects\xxx\DProject\Models\BIReport

我使用数据库优先的方法(使用现有数据库)启动了一个非常简单的ASP.NETMVC4应用程序。我已经使用ADO.Net实体数据模型模板生成了
.edmx
。该过程已在
xxxxxxx.edmx
选项下创建了一个
xxxxxxx.Designer.cs
文件。但是,.cs文件为空,并显示以下消息

// 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.
在消息之后,我已经更改了在
xxxxxxx.Designer.cs
文件中生成代码的属性

问题:

  • 这是正确的做法吗?这个文件的目的是什么
  • 我是否还需要通过右键单击“添加代码生成项”,然后选择EF DBContext生成器,从.edmx设计器页面生成强类型DBContext类
  • 数据库优先方法的具体过程是什么


    我看过很多帖子/博客/教程,所有这些看起来都很混乱,主要是针对CodeFirst方法

    Code First在技术上既是数据库优先,又不是数据库(它是灵活的)。您只需创建POCO(普通的旧C#对象)。这些类将按照您的需要映射出您的数据库表架构结构,无论数据库是否存在。如果你不知道自己在做什么,那么你可能不想这样做

    EDMX,以前是将填充设计器,但在VS 2012和更大的tt文件是默认值。您应该使用nuget的tt编辑器来真正从中获得更多信息

    或者我建议你做下面的事情

     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.
    

    在visual studio 2017中,要在designer.cs文件中创建代码(使用entity framework 5.0),我需要:

    • 开放模型.edmx和更改“代码生成策略”
    • 删除模型中的.tt文件

    我有一个让您满意的答案吗?您是否使用Visual studio 2010?在项目中是否添加了名为*.context.tt和*.tt的文件?数据库中是否有主键?如果不是,这可能是一个问题。EDMX将在EF Core 1.0中退出FYI(新名称为asp.net Core 1,它是EF Core 1而不是EF7)到现在(VS 2015)它被称为“代码生成策略:遗留ObjectContext”。很高兴知道。谢谢。我有时不得不用EDMX打开项目,在一些开发人员的机器上(重新生成文件)各种空间问题非常糟糕,需要安装运行时。它可能是实现的edmx版本,因为多年前我没有看到这么多问题。但我不相信它。我将首先使用代码,但老实说,我最近开始使用Dapper来解决Dapper-IQueryable等太多问题。。。所以回到EF和POCO等。。。