我正在创建我的第一个 MVC 项目,并且很好奇将我的 Code First 实体类公开给我的视图模型的正确方法。我有一个像这样的实体类:
public class Product
{
public int Id { get; set; }
public int CategoryId { get; set; }
[StringLength(50)]
public string ProductName { get; set; }
public Nullable<System.DateTime> DateAdded { get; set; }
[StringLength(50)]
public string AddedBy { get; set; }
}
是传入对象更好,还是传入新的属性类?
public class ProductViewModel
{
Product myProduct { get; set; }
}
public class ProductViewModel
{
public int Id { get; set; }
public int CategoryId { get; set; }
public string ProductName { get; set; }
public DateTime DateAdded { get; set; }
public string AddedBy { get; set; }
}