Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7188669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:08:07+00:00 2026-05-28T19:08:07+00:00

I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions

  • 0

I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions called TransactionID. Pretty standard.

I also have this code:

BrokerManagerDataContext db = new BrokerManagerDataContext();

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;

Basically, a TransactionAgent has a property/column named AgentCommission, which is null for all TransactionAgents in my database.

My goal is to perform the math you see in the foreach(var agent in taAgents) to patch up the value for each agent so that it isn’t null.

Oddly, when I run this code and break-point on agent.AgentCommission = (formula) 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.

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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:08:08+00:00Added an answer on May 28, 2026 at 7:08 pm

    IEnumerable<T>s do not guarantee that updated values will persist across enumerations. For instance, a List will return the same set of objects on every iteration, so if you update a property, it will be saved across iterations. However, many other implementations of IEnumerables return a new set of objects each time, so any changes made will not persist.

    If you need to store and update the results, pull the IEnumerable<T> down to a List<T> using .ToList() or project it into a new IEnumerable<T> using .Select() with the changes applied.

    To specifically apply that to your code, it would look like this:

    var transactions = (from t in db.Transactions
                        where t.SellingPrice != 0 
                        select t).ToList();
    
    var taAgents = (from ta in db.TransactionAgents
                    select ta).ToList();
    
    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;
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two tables both are related with primary-foreign key ralation and i have
I have two tables, the first has a primary key that is an identity,
I have two tables with a foreign key constraint how can I delete rows
I have two tables packages table: packageid, quantity transactions table: transactionid, packageid, quantity Whenever
i have two tables products and reviews each product has several reviews linked by
Lets say I have two tables, one for transactions, and another table who's primary
I have two tables: one contains employees information and another is transactions (sales) information
I have two tables: Holdings and Transactions Holdings data looks like: 06/30/2009, A, 100
I have two tables as below: Student: oneID (primary key), col1, col2, col3, subId,
This is the situation: I have two tables where the one references the other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.