S
S
Senture2019-11-24 14:13:46
Entity Framework
Senture, 2019-11-24 14:13:46

I added a new field to the table but I can't change its value, what should I do?

Good day!
I have the following situation: I
have an application for working with a database (and the application and the database are not mine, so I don’t understand their structure yet), I need to add a new field to one of the tables, add it through SQL Management studio, then open the project, go into the database model (file with the .edmx extension) right-clicked on an empty space and clicked the "Update model from the database" button.
5dda649eba354625793424.png
I selected the table I needed in the "Update" tab and clicked the "Finish" button.
After I tried to read the data of this field from all records as follows:

using (TestContext db = new TestContext ())
            {
                var ps = db.Project_test.ToList();
                foreach (Project_test p in ps)
                {
                    MessageBox.Show(p.TypeContract);
                }
            }

Everything is OK, but before that I added data to several records manually through SQL Management studio. After I tried to change the value of this field for all records as follows:
using (TestContext db = new TestContext ())
            {
                var ps = db.Project_test.ToList();
                foreach (Project_test p in ps)
                {
                    p.TypeContract = "test_value";
                }
                db.SaveChanges();
            }

But the values ​​​​do not change, and if I try to change the field that I did not add in the same way, then everything is ok.
What am I doing wrong? Tell me please!
PS Thank you so much for everything!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CHolfield, 2019-11-24
@Senture

Instead of a loop, use something like this:

using (TestContext db = new TestContext ())
            {
               var ps = db.Project_test;
               ps.ForEach(a=>a.TypeContract ="test_value");
               db.SaveChanges();
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question