locked
Update entity framework in code RRS feed

  • Question

  • As I can update the entity framework model from code not manually right click and update the database from
    • Moved by Amanda Zhu Tuesday, April 8, 2014 6:34 AM
    Monday, April 7, 2014 2:48 PM

Answers

  • For example, you have deleted an flied named OrderName of a table name Order in database, then you want to modified the .edmx file directly.

    So reading the .edmx file using XmlDocument or LINQ2XML as my first post.

    Then in SSDL and CSDL contents, find the OrderName node as:

    <Property Name="OrderName" Type="nvarchar" MaxLength="50" Nullable="false" />

    Removing this node from the XML file.
    Finding the mapping relationship in CSL context as:

     <ScalarProperty Name="OrderName" ColumnName="OrderName" />
    Removeing it and save this modified XML file. 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Friday, April 18, 2014 6:56 AM
    Wednesday, April 16, 2014 5:53 AM

All replies

  • Hi,

    I have moved this thread to ADO.NET Entity Framework and LINQ to Entities forum for better support.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 8, 2014 6:34 AM
  • Hello,

    >>As I can update the entity framework model from code not manually right click and update the database from

    Yes, in actual, the model is a XML file so if you want update the model, you just need to update the XML file using XmlDocument or LINQ2XML.

    For example, reading the model as a XmlDocument object:

    XmlDocument xmlDoc = new XmlDocument(); 
    
                try
    
                {
    
                    xmlDoc.PreserveWhitespace = true;
    
                    xmlDoc.Load(@"D:\BMX\Project\2014\04\EF6\DF\Model1.edmx");
    
                }
    
                catch (Exception e)
    
                {
    
                    Console.WriteLine(e.Message);
    
                }
    

    Then you can update the XML file as adding/removing/renaming correspondent nodes and save it. And do not forget to open the new model and save it to generate these entity classes since updating the model will do not update these classes generated by T4 templated.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 8, 2014 7:33 AM
  • ok thank you very much but I really was not very clear how to make this process easier if have me a simple project can appreciate them much
    Tuesday, April 8, 2014 12:34 PM
  • For example, you have deleted an flied named OrderName of a table name Order in database, then you want to modified the .edmx file directly.

    So reading the .edmx file using XmlDocument or LINQ2XML as my first post.

    Then in SSDL and CSDL contents, find the OrderName node as:

    <Property Name="OrderName" Type="nvarchar" MaxLength="50" Nullable="false" />

    Removing this node from the XML file.
    Finding the mapping relationship in CSL context as:

     <ScalarProperty Name="OrderName" ColumnName="OrderName" />
    Removeing it and save this modified XML file. 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Friday, April 18, 2014 6:56 AM
    Wednesday, April 16, 2014 5:53 AM