簡體   English   中英

ASP.NET VNext中的命令行腳手架

[英]Command line scaffolding in asp.Net VNext

我正在嘗試在Visual Studio 2015預覽版中創建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類,而不是視圖。

任何人都可以建議我錯了。

現在這是腳手架的一個已知問題,作為一種變通方法,您可以在生成的DbContext的OnModelCreating方法中配置Key,如下所示:

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

然后再搭棚。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM