添加代码生成项...
Added DbContext Generator
以下课程是为我的课程(课程,讲座,学生)创建的,名为"管理":
public class Management
{
public class Course
{
public int CourseId { get; set; }
public string CourseName { get; set; }
public string Description { get; set; }
public ICollection<Student> Students { get; set; }
public ICollection<Lecture> Lectures { get; set; }
}
public class Lecture
{
public int LectureId { get; set; }
public String LectureName { get; set; }
public String Description { get; set; }
public int CourseId { get; set; }
[System.ComponentModel.DataAnnotations.Schema.ForeignKey("CourseId")]
public virtual Course Course { get; set; }
}
public class Student
{
public int StudentId { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
public int CourseId { get; set; }
[System.ComponentModel.DataAnnotations.Schema.ForeignKey("CourseId")]
public virtual Course Course { get; set; }
}
}
在软件包管理器控制台中:
PM> Scaffold Controller Management
我收到以下错误:
Get-PrimaryKey : Cannot find primary key property for type 'RBS.PFM.Models.Management'. No properties appear to be primary keys.
At C:\Projects\RBS Project\RBS.PFM\packages\MvcScaffolding.1.0.9\tools\Controller\MvcScaffolding.Controller.ps1:71 char:15
+ $primaryKey = Get-PrimaryKey $foundModelType.FullName -Project $Project -ErrorIf ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-PrimaryKey], Exception
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.GetPrimaryKeyCmdlet
任何人都可以建议解决此问题的最佳方法。
亲切的问候, Sindhuja