Add the columns thru AlterTable...AddComlun() in UpdateFromX(), the retrived value Can't be saved

Topics: Core, General, Writing modules
Dec 7, 2012 at 5:51 AM
Edited Dec 7, 2012 at 5:56 AM

As the subject, the columns add in the UpdateFromX method, can't be saved, I can sure the part has read the value and set the value to property which related to the new columns, but can't be saved into DB(other columns can be saved, just new add columns value didn't save), and I saw the log file, no exception. Only I put the new columns to the create() method in migration file and drop the DB, I mean re-construct the Website to run the "Create()" mehod in the migration.cs, it can work well. Why that happened? it means any batch columns be added, I need to re-construct website? I think the new added columns didn't mapped to the field of tables of DB, What I need to do? This one has confuse me so long time.

I mean the column itself can create sucessful, but insert data to the column be added can't be saved.

Coordinator
Dec 7, 2012 at 6:29 AM

It's not quite clear what you're trying to do, but if you are trying to add data into a column that you just created, try to separate them in two different migration steps.

Dec 7, 2012 at 6:50 AM
Edited Dec 7, 2012 at 6:54 AM

I think may I don't say it clearly.

1. The page need to add new field which need to save to DB, e.g. Project Sponsor Name, then I create a new Property "ProjectSponsorName" in the  SomeLogicPartRecord and SomeLogicPart;
2. Then in the Migrations.cs I add the method "UpdateFrom1()"
public void UpdateFrom1() {
SchemaBuilder.AlterTable(typeof(SomLogicPart).Name, table => table.AddColumn("ProjectSponsorName"));
}
3. Run the web application, I found the table "...SomLogicPart" has succefully create the column "ProjectSponsorName", OK, from now on everything is very good.
4. At the page I input the "Project Sponsor Name" value, then click "Save" button and debug at controller.cs, the property "ProjectSponsorName" of SomLogicPart has be filled value(I mean it has get the data from UI), but after save, I saw the table in the DB, the value of "ProjectSponsorName" is null, and other column saved sucessfully.
5. what confuse me is why the column has create sucessfully, and the fill data to the part is sucessfully, but save to the DB is failture.

6. At last, I rewrite the Migratins.cs, then at once creat all the columns in the Create() method, drop the DB, delete the App_Data folder to re-construct the Web site, "ProjectSponsorName" can be saved sucessfully.


May I lost some step or something other I need to do(e.g. enable some module)?

Dec 7, 2012 at 8:34 AM

It's hard to say what exactly went wrong without seeing the entire module. In any case, it should work perfectly fine wen you just add a column to a table using a migration step. I have done this hundreds of times, without having to do anything special. My guess would be that you made a mistake somewhere. Should you be able to reproduce the problem I would be happy to receive a copy of the module to see what exactly went wrong. Good to see you at least found a solution.