Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Entity Framework to update both normal and relational fields
    text
    copied!<p>I have a problem figuring out the proper way to get foreign key fields to update using the Entity Framework. I do not have a problem updating them in the database, but rather on the interface.</p> <p>Here are the relevant tables to my question file:///C:/Users/Mike/Desktop/RelevantTables.bmp</p> <p>I have a "Team" form with a Master/Detail type view (master = Team, detail = Player), and show the Players in a ListView. When you double click a Player, I show the "Edit Player" form.</p> <p>Here is how I am loading the data in my TeamForm Window_Loaded event:</p> <pre><code>var TeamQuery = from t in ScoresDB.Team .Include("School").Include("TeamLevel").Include("Player.PlayerPosition") .Where(x =&gt; x.TeamID == TeamID) select t; TeamData = new TeamCollection(TeamQuery, ScoresDB); TeamViewSource = (CollectionViewSource)FindResource("TeamViewSource"); PlayerViewSource = (CollectionViewSource)FindResource("PlayerViewSource"); TeamViewSource.Source = TeamData; TeamView = (ListCollectionView)TeamViewSource.View; TeamView.CurrentChanged += new EventHandler(TeamView_CurrentChanged); PlayerView = (BindingListCollectionView)PlayerViewSource.View; </code></pre> <p>This is what I am doing when the user wants to edit a player:</p> <pre><code>// If the user made changes to the player, then refresh our view if (PlayerForm.EditPlayer(SelectedPlayer.PlayerID)) { ScoresDB.Refresh(System.Data.Objects.RefreshMode.ClientWins, PlayerView); } </code></pre> <p>My problem is that, although every field that is not a foreign key does reflect the changes in the ListView, the PlayerPosition does not. It is being properly changed in the database. Do I need to re-query the database every time?</p> <p>I get the distinct feeling that I am doing all of this quite poorly as I am just starting to trudge through WPF and EF. </p> <p>If anyone has a clue what is going on or just wishes to tell me how silly I am being doing it this way, that is fine with me!</p> <p>Thanks in advance, Mike</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload