I have a pretty simple model consisting of a Post with a User navigation property (public User CreatedByUser { get; set; }). The User object also has a navigation property for the collection of posts created by that user (public ICollection<Post> PostsCreated { get; set; }). If I make a request (db.Posts.Include(x => x.CreatedByUser)), the CreatedByUser contains the appropriate User, but the PostsCreated collection has also been populated even though I haven't explicitly loaded it via Include. Since I have opted to disable lazy loading in my context, I would only expect that the User object be populated, but I would not expect the collection of posts created to be populated. I've included the Post mapping below:
this.HasRequired(t => t.CreatedByUser).WithMany(t => t.PostsCreated).HasForeignKey(d => d.CreatedById);
To further test this, I have a complex type collection (public ICollection<PromoPost> PromoPosts { get; set; }) on the Post object. If I don't include that property explicitly, the collection is empty; however, if I include it the collection is populated as expected. This is the behavior I would expect on the collections associated with included entities.
I'm hoping someone can confirm if this is expected behavior or if this is something that may need to be addressed another way.
this.HasRequired(t => t.CreatedByUser).WithMany(t => t.PostsCreated).HasForeignKey(d => d.CreatedById);
To further test this, I have a complex type collection (public ICollection<PromoPost> PromoPosts { get; set; }) on the Post object. If I don't include that property explicitly, the collection is empty; however, if I include it the collection is populated as expected. This is the behavior I would expect on the collections associated with included entities.
I'm hoping someone can confirm if this is expected behavior or if this is something that may need to be addressed another way.