mapping private property entity framework code first

前端 未结 7 1772
遇见更好的自我
遇见更好的自我 2020-11-27 17:23

I am using EF 4.1 and was look for a nice workaround for the lack of enum support. A backing property of int seems logical.

    [Required]
    public VenueT         


        
相关标签:
7条回答
  • 2020-11-27 17:53

    Another workaround might be to set your field as internal:

        [NotMapped]
        public dynamic FacebookMetadata {
            get
            {
                return JObject.Parse(this.FacebookMetadataDb);
            }
            set
            {
                this.FacebookMetadataDb = JsonConvert.SerializeObject(value);
            }
        }
    
        ///this one
        internal string FacebookMetadataDb { get; set; }
    

    and add it to tour model:

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.ManyToManyCascadeDeleteConvention>();
    
            ///here
            modelBuilder.Entity<FacebookPage>().Property(p => p.FacebookMetadataDb);
    
            base.OnModelCreating(modelBuilder);
        }
    
    0 讨论(0)
提交回复
热议问题