Force the load collection linq

Posted on 2009-05-01
Last Modified: 2013-11-11

I've 2 tables

by exemple:

Categories and Models

One categories has many Models
One models has only one categories(so we've a foreign key in models)

So I use LINQ to Entity, but I've a problem.

If I've a category object and I do:


I've "0", and in the database, I've correct things.

And if I debug when I do this, a property named "isLoaded" that have the value "false".

So I think the collection isn't loaded.

Must we do anything special? How do we load this collection?

Question by:Nargzul
    LVL 4

    Expert Comment

    Read this article on loading categories:

    Load using this syntax:  Category models = context.Categories.Where(c => c.Name == "Model").First();

    LVL 21

    Expert Comment

    You might want to do some eager loading - I explain it here:
    dbDataContext db = new dbDataContext();
    DataLoadOptions dlo = new DataLoadOptions();
    dlo.LoadWith<category>(i => i.Model);
    db.LoadOptions = dlo; 

    Open in new window

    LVL 1

    Accepted Solution

    I've used the ".Include("blabla")".

    It's exactly what I need

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now