0

关于另一个SO帖子,我需要更新我的模型,以便“新”列 ActiveBool 不会尝试与数据库表匹配。

该模型:

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); }

        }
    }

有可以使用的 DataAnnotation 吗?

4

1 回答 1

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); } 

        } 
    } 
于 2012-04-10T14:38:31.553 回答