Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 防止MVC 3和实体框架在模型和数据库之间匹配_Entity Framework_Asp.net Mvc 2 - Fatal编程技术网

Entity framework 防止MVC 3和实体框架在模型和数据库之间匹配

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

关于另一篇文章,我需要更新我的模型,这样“新”列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); }

        }
    }

是否有可以使用的数据批注?

您需要使用[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); } 

        } 
    }