title: Updating an item property within IEnumerable but the property doesn't stay set?
body: <p>I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions called TransactionID. Pretty standard.</p>
  
  <p>I also have this code:</p>
  
  <p>BrokerManagerDataContext db = new BrokerManagerDataContext();</p>
  
  <pre><code>var transactions = from t in db.Transactions
                     where t.SellingPrice != 0 
                     select t;
  
  var taAgents = from ta in db.TransactionAgents
                 select ta;
  
  foreach (var transaction in transactions)
  {
      foreach(var agent in taAgents)
      {
          agent.AgentCommission = ((transaction.CommissionPercent / 100) * (agent.CommissionPercent / 100) * transaction.SellingPrice) - agent.BrokerageSplit;
      } 
  }
  
  dataGridView1.DataSource = taAgents;
  </code></pre>
  
  <p>Basically, a TransactionAgent has a property/column named AgentCommission, which is null for all TransactionAgents in my database.</p>
  
  <p>My goal is to perform the math you see in the <code>foreach(var agent in taAgents)</code> to patch up the value for each agent so that it isn't null.</p>
  
  <p>Oddly, when I run this code and break-point on <code>agent.AgentCommission = (formula)</code> it shows the value is being calculated for AgentCommissision and the object is being updated but after it displays in my datagrid (used only for testing), it does not show the value it calculated.</p>
  
  <p>So, to me, it seems that the Property isn't being permanently set on the object. What's more, If I persist this newly updated object back to the database with an update, I doubt the calculated AgentCommission will be set there.</p>
  
  <p>Without having my table set up the same way, is there anyone that can look at the code and see why I am not retaining the property's value?</p>