Code First and EF 5.0 not loading navigation properties

前端 未结 4 959
悲&欢浪女
悲&欢浪女 2021-01-14 13:39

I am trying to load a navigation property through Code First and EF 5.0 The child object is loading as null. below is the code.

  [Table(\"ls_roles\")]
    p         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 14:38

     [Table("ls_roles")]
    public class Role
    {
        [Required]
        [Key]
        public int RoleID { get; set; }
    
        [Required]
        public String BarColor { get; set; }
    
    
        public virtual ICollection Employees { get; set; }
    }
    
    [Table("ls_ScheduleEmployee")]
    public class ScheduleEmployee
    {
        [Key]
        [Required]
        public int Id { get; set; }
    
        [Required]
        [ForeignKey("Role")]
        public int RoleId { get; set; }
    
    
        public virtual  Role Role { get; set; }
    }
    

提交回复
热议问题