Updating Entity Framework Model

前端 未结 6 2014
悲&欢浪女
悲&欢浪女 2020-12-31 00:20

I have just started using EF and found it cool, but I ran into a problem,

Problem:
I changed my DB schema of a column inside the table User, It

相关标签:
6条回答
  • 2020-12-31 00:51

    go to MyModel.edmx xml file, change Binary to String solved my issue

    0 讨论(0)
  • 2020-12-31 00:55

    No need to worry about it. Select the affected table in the model. If you observe, there you will find a new column name post fix with an integer (This behavior is only because of the change in the datatype of that column).

    Example if your column name is "Samplecolumn", after updating the model from the database you will get a new column with Samplecolumn1. You can now simply remove the old column "Samplecolumn" and rename the new column "Samplecolumn1" to "Samplecolumn" using the properties window under general category.

    Just build your app. The error will be gone.

    0 讨论(0)
  • 2020-12-31 00:56

    right click properties from changed table on Model.edmx[Diagram] and "Update model from database" . save and run

    0 讨论(0)
  • 2020-12-31 00:57

    I've run into similar issues before, and found that the way to solve it was to delete the table from the model. Save and close the model. Then reopen the model and re-add the table.

    0 讨论(0)
  • 2020-12-31 01:00

    A lot of files in the EF model get f*****d. Removing and adding the entity was not enough. The entities was duplicated like table, table1, table_result, table1_result, table_result1, and so on... Model update was updating the duplicated references instead of the original.

    I have to open notepad and fix manually these files:

    EFModel.Context.cs
    EFModel.edxm
    

    And delete these files:

    obj\Debug\edmxResourcesToEmbed\MYEfModel.csdl
    obj\Debug\edmxResourcesToEmbed\MYEfModel.msl
    obj\Debug\edmxResourcesToEmbed\MYEfModel.ssdl
    
    0 讨论(0)
  • 2020-12-31 01:11

    Shawn de Wet's solution works fine but In case you dont want to remove the table (for example relationship to some other tables..) you can use another solution: Open your edmx file with xml Editor, Ctrl + F to find a line similar to

    Property Name="Email" Type="Binary" Nullable="false" MaxLength="50" FixedLength="false"

    Update it to:

    Property Name="Email" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false"

    Save it and rebuild.

    0 讨论(0)
提交回复
热议问题