Entity framework 防止MVC 3和实体框架在模型和数据库之间匹配
关于另一篇文章,我需要更新我的模型,这样“新”列ActiveBool就不会试图与数据库表匹配 模型:Entity framework 防止MVC 3和实体框架在模型和数据库之间匹配,entity-framework,asp.net-mvc-2,Entity Framework,Asp.net Mvc 2,关于另一篇文章,我需要更新我的模型,这样“新”列ActiveBool就不会试图与数据库表匹配 模型: public class StatusList { [Key] public int StatusID { get; set; } [Required] public byte Active { get; set; } //I want this column to be ignored b
public class StatusList
{
[Key]
public int StatusID { get; set; }
[Required]
public byte Active { get; set; }
//I want this column to be ignored by Entity Framework
public bool ActiveBool
{
get { return Active > 0; }
set { Active = value ? Convert.ToByte(1) : Convert.ToByte(0); }
}
}
是否有可以使用的数据批注?您需要使用[NotMapped]批注:
public class StatusList
{
[Key]
public int StatusID { get; set; }
[Required]
public byte Active { get; set; }
//I want this column to be ignored by Entity Framework so I add [NotMapped]
[NotMapped]
public bool ActiveBool
{
get { return Active > 0; }
set { Active = value ? Convert.ToByte(1) : Convert.ToByte(0); }
}
}