문제

I have three tables in my database:

  • Post
  • Author
  • Tags

I'm using ASP.NET MVC 4 with EF 5 and my Post model (generated automatically) looks like this one:

public partial class BlogPost
{
    public BlogPost()
    {
        this.Tags = new HashSet<Tag>();
    }

    ...

    public virtual Author Author { get; set; }
    public virtual ICollection<Tag> Tags { get; set; }
}

My context and dbSet are definded. I'm trying to get all the posts in the database with this query

dbSet.ToList()

I thought that Author will be null and Tags will be empty, because I didn't use Include() to use eager loading. But if I debug, I found that Author isn't null and Tags got two elements. I don't understand why.

In Tag entity I got a navigation property to get all the posts that got that Tag. It looks like is filling all the data... but I don't notice any performance problem when I test the page, it load very fast.

Maybe it's not an error... am I just missing something?

도움이 되었습니까?

해결책

Please check this answer:

Lazy Loading means that entities will be automatically loaded when you first access collection or navigation property, and that will happen transparently, as though they were always loaded with parent object.

Using "include" is loading on demand, when you specify properties you want to query.

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top