我正在使用ASP.NET MVC3。我有一个模型有一个我不想存储在数据库中的属性。我可以在物业上放置一个属性来实现这个目标吗?感谢。
答案 0 :(得分:29)
public class Person
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[NotMapped]
public string FullName { get; set; }
}
该属性位于命名空间System.ComponentModel.DataAnnotations
答案 1 :(得分:1)
只是添加更多选项...这就是为什么我更喜欢将我的域模型与我的视图模型分开。我的视图模型通常具有渲染不属于域模型的视图所需的其他字段。我通常使用的设计很好地描述了here。