I am loading a graph of related entities from the database using ADO.NET MVC and the Entity Framework. One of the entities needs to be modified in memory, but not have changes persisted back to the database when other entities in the graph are changed.
At this time I have attempted to use the MergeOption.NoTracking and the MergeOption.OverwriteChanges but they both seem to be ignored and any changes in the entity set that should not be modified being persisted to the store.
A snippet of the code that I use to load the entity graph from the database is given below:
QuizDBEntities entities = new QuizDBEntities();
ObjectParameter[] searchParameters = { new ObjectParameter("contestantID", contestantID) };
entities.QuestionSet.MergeOption = MergeOption.NoTracking;
var query = entities.ContestantSet
.Include("Quiz.Questions.Categories.Options.Answer")
.Include("Answers")
.Include("Quiz.Questions.Filters.FilterAnswers")
.Where("it.ContestantID == @constestantID", searchParameters);
Contestant contestant = query.First();
I have also attempted to set the MergeOption after the query is constructed but before being executed.
Any help would be greatly appreciated.