指定類 public class Designation
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int id { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
我有一個簡單的DB結構。導航財產所有者階級,和我見面的時候我試圖創造的運輸清單與業主加入OWNERNAME因爲OWNERID在交通運輸,不需要一個問題... public Transport()
{
[Key]
public int TransportID { get; set; }
public string PlateNo { get; set; }
我使用代碼優先在運行時生成數據庫和數據。 我的兩個類/模型有一對多的關係。由於FK不能爲空,因此我在插入學生之前首先插入標準,我也手動輸入FK ID。但我仍然得到System.NullReferenceException,我只是不明白爲什麼? 我試過Google搜索,但是我找不到有關從頭開始在外部關係中插入數據的相關文章。 我的實體類/型號 public class Student {
我想在用戶和帖子之間生成一個聯結表,我想在帖子表中添加userId。 我有這樣的代碼 public class Post
{
public Post()
{
this.ApplicationUser = new HashSet<ApplicationUser>();
}
public int PostId { get; set; }
我試圖設置一些實體框架代碼第一模型的導航屬性。我想讓他們看起來像這個例子: public class Course
{
[Key]
public int CourseId { get; set; }
public string CourseName { get; set; }
public virtual ICollection<Student> Stud