3

Is it possible to disable proxy in Entity Framework in one dedicated query? I don't want to impact on rest of solution.

I want to turn off proxy objects and get 'native' Goal and GoalProgressItem. How to get non-proxy objects.

var goalWithProgressItemsPairs = _dbContext.GoalProgressItems
    .Include(p => p.Goal)
    .Where(p => p.Date >= range.From && p.Date <= range.To)
    .Select(p =>
        new
        {
            Goal = p.Goal,
            ProgressItem = p
        }
    )
    .ToList();
2
  • What do you mean by native and proxy? What do you want to occur that your above query is (or is not) doing? Commented May 31, 2017 at 15:34
  • @Igor In my DbContext I have defined DbSet<Goal> Goals. I mean "Goal" as 'native' type, defined by me. Query return proxy type which inherits from Goal. Commented May 31, 2017 at 15:37

1 Answer 1

2

Did you try to set the 'ProxyCreationEnabled' property of the Configuration property of your _dbContext before your call ? Something like

_dbContext.Configuration.ProxyCreationEnabled = false;
// Your query
_dbContext.Configuration.ProxyCreationEnabled = true;
Sign up to request clarification or add additional context in comments.

Comments

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.