2

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I knew that I was missing something. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.