首页 新闻 赞助 找找看

code first中的导航属性疑问

0
悬赏园豆:10 [已关闭问题] 关闭于 2016-05-03 22:41

我有两个model
    public partial class Nav
    {
        [Key]
        public int Id { get; set; }

        [StringLength(50)]
        public string Name { get; set; }

        public string Remark { get; set; }
        public ICollection<Section> Sections { get; set; }
    }

    public partial class Section
    {
        [Key]
        public int Id { get; set; }

        [StringLength(50)]
        public string Name { get; set; }

        public string Remark { get; set; }
        [ForeignKey("Nav")]
        public int NavId { get; set; }
        public Nav Nav { get; set; }

  }

由上面代码可知我的两个model存在外键关系,但我find一个nav对象后访问其中的Sections属性,却是null,但我用modelfirst创建的项目是可以直接find对象后再访问其中的导航属性ICollection<Section> Sections

望高手解答

huanent的主页 huanent | 初学一级 | 园豆:47
提问于:2016-05-03 22:20
< >
分享
所有回答(1)
0

virtual 修饰ICollection

huanent | 园豆:47 (初学一级) | 2016-05-03 22:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册