0

In relation to another SO post I need to update my model so that the 'new' column ActiveBool doesn't try to get matched against a database table.

The model:

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

        }
    }

Is there an DataAnnotation that can be used?

Community
  • 1
  • 1
John M
  • 14,338
  • 29
  • 91
  • 143

1 Answers1

0

You need to use the [NotMapped] annotation:

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

        } 
    } 
John M
  • 14,338
  • 29
  • 91
  • 143