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

前端 未结 2 1995
抹茶落季
抹茶落季 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 IsActive { get; set; }
        public string ESID { get; set; }
        public string RID { get; set; }
        public byte LevelSearchGroup { get; set; }
    }
    

提交回复
热议问题