How to map a column name with spaces in it to a POCO property?

前端 未结 2 1960
抹茶落季
抹茶落季 2021-01-05 07:57

I am working on database table which has a column name with a space in it, for example \"Level Description\".

I cannot change the column name. Now I have an Entity F

相关标签:
2条回答
  • 2021-01-05 08:30

    You don't have to have your model property names exactly matching your table column names; there is a [Column] attribute you can apply to map a property to the column:

    [Table("StudyLevel")]
    public class StudyLevelModel
    {
        [Key]
        public byte StudyLevelID { get; set; } 
        [Column("Level Description")]
        public string LevelDescription { get; set; }
        public string SLevelType { get; set; }
        public Nullable<bool> IsActive { get; set; }
        public string ESID { get; set; }
        public string RID { get; set; }
        public byte LevelSearchGroup { get; set; }
    }
    
    0 讨论(0)
  • 2021-01-05 08:42

    Use the ColumnAttribute to set the name:

     [Column(Name="Level Description")]
     public string LevelDescription { get; set; }
    
    0 讨论(0)
提交回复
热议问题