1

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?

1 Answer 1

2
public List<Case> GetCases()
{
    db.Configuration.ProxyCreationEnabled = false;
    return db.Cases.AsNoTracking().ToList();
}
Sign up to request clarification or add additional context in comments.

2 Comments

That brought me back this error in my JSON return: "innerException":{"message":"An error has occurred.","exceptionMessage":"When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects." I'm not sure what that means exactly.
Updated my reply

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.