【问题标题】:generating entity from cs file code in edmx从 edmx 中的 cs 文件代码生成实体
【发布时间】:2015-02-21 12:54:46
【问题描述】:

我启动了一个示例实体框架项目。我有 EntityModel.edmx 文件,当我单击 EntityModel.Designer.cs 文件时,它会打开一个写入的文件:

// T4 code generation is enabled for model 'c:\users\scala\documents\visual studio 2013\Projects\entityFramework\entityFramework\EntityModel.edmx'. 
// To enable legacy code generation, change the value of the 'Code Generation Strategy' designer
// property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model
// is open in the designer.

// If no context and entity classes have been generated, it may be because you created an empty model but
// have not yet chosen which version of Entity Framework to use. To generate a context class and entity
// classes for your model, open the model in the designer, right-click on the designer surface, and
// select 'Update Model from Database...', 'Generate Database from Model...', or 'Add Code Generation
// Item...'.

我无法获取实体代码。如何获取实体代码?我无法更改“代码生成策略”设计器 属性窗口中的“旧版 ObjectContext”。

【问题讨论】:

  • 我建议你先使用代码而不是先使用数据库来进行完全控制

标签: asp.net entity-framework


【解决方案1】:

仔细阅读 cmets 中的内容:

要为您的模型生成上下文类和实体类,请在设计器中打开模型,右键单击设计器图面,然后选择“从数据库更新模型...”、“从模型生成数据库...” ',或'添加代码生成项...'。

“添加代码生成项...”可以解决问题。您基本上应该选择并添加一个或多个 T4 模板来实际生成实体。更多信息here。也看看this answer。这可能有助于让事情变得清晰。

【讨论】:

  • 任何时候,也看看我最近添加到答案中的链接 - 那里有更详细的解释。
猜你喜欢
  • 2011-07-10
  • 1970-01-01
  • 2016-05-13
  • 2011-11-25
  • 2016-09-28
  • 1970-01-01
  • 2010-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多