我制作了一个CarManagement计划,这是一个人员列表,他们每个人都拥有一些汽车。所以,我在下面的图片中写了2类人物和汽车。我不知道到底是什么?请给我一些建议
public class Person
{
public int PersonId { get; set; }
[Required]
public string Name { get; set; }
[Range(1,120)]
public int Age { get; set; }
public int Asset { get; set; }
public int CarNumber { get; set; }
public virtual ICollection<Car> Cars { get; set; }
}
public class Car
{
//public int CarID;
// Phai la thuoc tinh
public int CarId { get; set; }
public int PersonID { get; set; }
[Required]
public string Model { get; set; }
[Required]
public string Color { get; set; }
public int SerialNumber { get; set; }
[DataType(DataType.Date)]
public DateTime RegistryDay { get; set; }
public virtual Person Person { get; set; }
}
答案 0 :(得分:0)
简单来说,模型类用于表示数据库中的表。模型类的每个实例都对应于数据库表中的一行。
根据您的示例Car类来表示数据库中的Cars表。 Cars类的每个对象都对应于数据库表中的一行,Cars类的每个属性都将映射到表中的一列。