I have added a new column to a table in my database. The table is already defined in the existing Entity Framework model. I've been through most of the items here on how to do this and it still fails.
A little background, this entity model has not been updated in at least 3 years. So aside from the column I'm adding I know there have been a number of other columns that have been added in that time, but never included. I took over the project about 9 months ago and have never been able to successfully update the model.
First attempt:
Result:
Second Attempt
Result
Third Attempt
Result
Fourth Attempt
Results
Final Attempt
Result
Any help or direction that could be provided would be greatly appreciated as I'm at a critical point and have to get the model updated.
The basic syntax of an ALTER TABLE command to add a New Column in an existing table is as follows. ALTER TABLE table_name ADD column_name datatype; The basic syntax of an ALTER TABLE command to DROP COLUMN in an existing table is as follows.
Add a column to the left or right Click in a cell to the left or right of where you want to add a column. Under Table Tools, on the Layout tab, do one of the following: To add a column to the left of the cell, click Insert Left in the Rows and Columns group.
The "Update Model from Database" is hard/slow to use and is prone to errors. It generates other stuff that you probably don't want/need. So manually adding the column that you need will work better. I suggest you do it outside the VS editor since depending on how many models/tables, it can be very slow opening the file in VS.
So in Windows Exlorer, right-click on the *.edmx
file and open with Notepad (or Notepad++/Textpad).
Search for the text <EntityType Name="YourTableNameToAddColumn">
.
Add the property <Property Name="YourNewColumnName" Type="varchar" MaxLength="64" />
Search for the text <MappingFragment StoreEntitySet="YourTableNameToAddColumn">
Add mapping to the new column <ScalarProperty Name="YourNewColumnName" ColumnName="YourNewColumnName"/>
Save the *.edmx
file
So in Windows Exlorer,right click on the *.edmx file and open with Notepad (or Notepad++/Textpad).
Search for the text <EntityType Name="YourTableNameToAddColumn">
.
Add the property <Property Name="YourNewColumnName" Type="varchar" MaxLength="64" />
.
Search for the text again <EntityType Name="YourTableNameToAddColumn">
, there is a second one.
Add the property <Property Name="YourNewColumnName" Type="varchar" MaxLength="64" />
to it.
Search for the text <MappingFragment StoreEntitySet="YourTableNameToAddColumn">
.
Add mapping to the new column <ScalarProperty Name="YourNewColumnName" ColumnName="YourNewColumnName"/>
.
Save the *.edmx file
After that update the edmx model of your table public string YourNewColumnName { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With