protected void CreateDbContext() { DbContext = new DTDbContext(); // Do NOT enable proxied entities, else serialization fails DbContext.Configuration.ProxyCreationEnabled = false; // Load navigation properties explicitly (avoid serialization trouble) DbContext.Configuration.LazyLoadingEnabled = false; // Because Web API will perform validation, we don't need/want EF to do so DbContext.Configuration.ValidateOnSaveEnabled = false; //DbContext.Configuration.AutoDetectChangesEnabled = false; // We won't use this performance tweak because we don't need // the extra performance and, when autodetect is false, // we'd have to be careful. We're not being that careful. }
private void OnReadButtonClicked(object sender, RoutedEventArgs e) { using (var dbContext = new DTDbContext()) { foreach (var topic in dbContext.Topics) { Debug.WriteLine(topic.Name); if (topic.Questions == null) continue; foreach (var question in topic.Questions) { Debug.WriteLine(question.Text); } } foreach (var question in dbContext.Questions) { Debug.WriteLine(question.Text); Debug.WriteLine(question.Topic.Name); } } }