【问题标题】:Command line scaffolding in asp.Net VNextasp.Net VNext 中的命令行脚手架
【发布时间】:2015-04-04 22:43:22
【问题描述】:

我正在尝试在 Visual Studio 2015 Preview 中创建一个 Web 应用程序。我正在尝试使用命令行脚手架创建视图。 我使用了以下命令:

k gen controller -name ProductController -m ViewModels.Product -dc ProductContext -f -udl

ViewModels.Product 类在另一个项目中定义并在 UI 项目中引用。运行命令时出现以下错误:

Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to figure out the EntityFramework metadata for the model and DbContext.
The entity type 'ViewModels.Product' requires a key to be defined.

Product 类中,我添加了对System.ComponentModel.DataAnnotations 的引用,并使用[key] 属性定义了一个属性。 它正在创建 DataContext 类,而不是视图。

请任何人指出我错在哪里。

【问题讨论】:

    标签: c# asp.net-core asp.net-mvc-scaffolding visual-studio-2015


    【解决方案1】:

    这是目前脚手架的一个已知问题,作为一种解决方法,您可以像这样在生成的 DbContext 的 OnModelCreating 方法中配置 Key:

    builder.Entity<Product>().Key(p => p.MyKeyName);
    

    然后再次脚手架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-26
      • 2019-12-29
      • 2013-06-20
      • 1970-01-01
      • 2016-05-08
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多