0

Suppose that i have

public IQueryable<Application> GetApplications() {
    var applications = _context.Applications.Where(v => v.Exported == false);
    // Now i want to flag exported = true because i am exporting them
    foreach (var application in applications){
        _context.Applications.SingleOrDefault(v => v.ApplicationId == application .ApplicationId).Exported = true;
}
    _context.SaveChanges();
    return applications;
}

I am not getting any applications because _context.SaveChanges(); ( i suppose) changed the applications variable. How can i change the Database without changing my local variable.

2
  • Well that seems very weird and should not happen. Make sure that applications is not empty collection at first line of method. Jul 2, 2015 at 11:34
  • its not empty. while debugging i can see the applications variable populated and after SaveChanges applications is empty.
    – Iezekiel
    Jul 2, 2015 at 11:38

1 Answer 1

1

Call ToList to execute query before changing items:

var applications = _context.Applications.Where(v => v.Exported == false).ToList();
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.