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 に答える