我還是使用實體框架和MVC 4 Razor創建模型的新手。我在如何保存模型的歷史記錄時遇到問題。如何創建在特定表格或字段上有歷史記錄的模型?例如:如果我想創建關於學校變化的歷史記錄。它仍然不清楚我將如何創建保存歷史的模型。如何觸發我必須在具有相同數據的不同型號上執行保存功能?如何在MVC上創建特定模型的歷史模型4
非常感謝你提前。
如果任何人都可以成爲模型和模型歷史的簡單示例以及它如何運作,我將非常感激。像銷售或銷售歷史一樣。
這裏是我的代碼
一對多 公共類兒童 { [關鍵] 公衆詮釋childID的{獲得;組; }
[Required,Display(Name="Project Code")]
public string ProjectCode { get; set; }
public string Status { get; set; }
[DataType(DataType.Date)]
public DateTime StatusDate { get; set; }
public string FamilyName { get; set; }
public string GivenName { get; set; }
public string MiddleName { get; set; }
[DataType(DataType.Date)]
public DateTime Birthdate { get; set; }
public string Gender {get;set;}
public string Address { get; set; }
public string Section { get; set; }
public int SchoolLevelID { get; set; }
public int SchoolYearID { get; set; }
public int AreaID { get; set; }
public int SchoolID { get; set; }
public int GradeLevelID { get; set; }
//Foreign Key - One to Many
public virtual SchoolLevel SchoolLevel { get; set; }
public virtual SchoolYear SchoolYear { get; set; }
public virtual Area Area { get; set; }
public virtual School School { get; set; }
public virtual GradeLevel GradeLevel{get;set;}
//Child is foreign key at the table
public virtual ICollection<Guardian> Guardians { get; set; }
}
public class SchoolLevel
{
public int SchoolLevelID { get; set; }
public string SchoolLevelName { get; set; }
public virtual ICollection<Child> Children { get; set; }
}
public class SchoolYear
{
public int SchoolYearID { get; set; }
public string SchoolYearName { get; set; }
public virtual ICollection<Child> Children{get;set;}
}
public class Area
{
public int AreaID{get;set;}
public string AreaName { get; set; }
public virtual ICollection<Child> Children{get;set;}
}
public class School
{
public int SchoolID { get; set; }
public string SchoolName{get;set;}
public virtual ICollection<Child> Children { get; set; }
}
public class GradeLevel
{
public int GradeLevelID{get;set;}
public string GradeLevelName { get; set; }
public virtual ICollection<Child> Children { get; set; }
}
public class ChildDbContext : DbContext
{
public DbSet<Child> Children { get; set; }
public DbSet<SchoolLevel> SchoolLevels { get; set; }
public DbSet<SchoolYear> SchoolYears { get; set; }
public DbSet<Area> Areas { get; set; }
public DbSet<School> Schools { get; set; }
public DbSet<GradeLevel> GradeLevels { get; set; }
public DbSet<Guardian> Guardians { get; set; }
}
您的意見不清楚。寫任何真實的樣本。 –
對於示例模型子項,您可以爲該子項添加地址。目前的模型會很好。但我想要的是一種存儲子地址的方法,例如我更新了子地址,我如何創建一個模型作爲子地址的歷史記錄。所以每次我想要一個孩子的地址更新它通過AddressHistoryModel記錄我不知道我將如何觸發這一點。謝謝 – Arvin