Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating an item property within IEnumerable but the property doesn't stay set?
    text
    copied!<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>
 

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