【发布时间】:2014-03-28 04:02:55
【问题描述】:
在使用 Entity Framework 和 MVC 4 Razor 创建模型方面我还是个新手。我对如何保存模型的历史有疑问。如何创建具有特定表或字段历史记录的模型?例如:如果我想创建关于学校变化的历史。我仍然不清楚我将如何创建保存历史的模型。我必须如何在具有相同数据的不同模型上执行保存功能?
非常感谢您。
如果有人可以提供模型和模型历史及其运作方式的简单示例,我将不胜感激。就像销售或销售历史一样。
这是我的代码
一对多 公共课儿童 { [钥匙] 公共 int 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; }
}
【问题讨论】:
-
你的意见我不清楚。编写任何真实示例。
-
例如模型 Child 您可以为该孩子添加地址。当前的模型会做得很好。但是我想要的是一种存储子地址的方法,例如我更新了子地址,如何创建一个模型来作为子地址的历史记录。所以我希望每次更新孩子的地址时都会通过 AddressHistoryModel 记录它,我不知道我将如何触发它。谢谢
标签: asp.net-mvc-4 model entity