John Ernest
John Ernest

Reputation: 827

WebApi Lazy Loading

I'm just starting out with ASP.NET MVC WebApi and EntityFramework and wanting to use a data-first model to bring objects out of an existing database. This works fine but it takes a decently long time to bring back the data with only 500 records because the data is related over several tables. I want it to bring back only the main table in my pull for performance in searching, so I do something like this:

    // GET: api/Cases
    public IQueryable<Case> GetCases()
    {
        db.Configuration.LazyLoadingEnabled = true;
        db.Configuration.ProxyCreationEnabled = true;
        return db.Cases;
    }

However, it's still pulling back all of the related tables. Any idea how to change that?

Upvotes: 1

Views: 2214

Answers (1)

ErikEJ
ErikEJ

Reputation: 41799

public List<Case> GetCases()
{
    db.Configuration.ProxyCreationEnabled = false;
    return db.Cases.AsNoTracking().ToList();
}

Upvotes: 2

Related Questions