locked
EF4 - update model from database ignores some changes RRS feed

  • Question

  • Hi,

    I use EF4 with VS2010 Ultimate. I tried to propagate some modifications in database to EF model (using 'Update Model from database'), however some changes like column name changes are clearly ignored. Is it bug or feature? I googled it for a while but found various behaviors in various combinations of versions of VS and EF, so it's not clear what's the final design.

    I could understand that it could be difficult to detect column renaming but the process could at least create new property for the renamed column. Current behavior is pretty annoying when developers have to keep in mind all such changes or get errors late in runtime..

    Did I miss something? Isn't there any setting to modify this behavior? I can't believe this would be acceptable for the developers community..

    Thanks

    eXavier

    Wednesday, October 13, 2010 2:42 PM

Answers

  • Hi eXavier,

    You can use the wizard to add objects that were created in the database after you originally built the model. For example, if a new table has been added to the database, the Update Model Wizard will discover that the table is not already listed in the Store Schema Definition Layer (SSDL) of the model and will display it in the Add page of the wizard. If you select this new table, the wizard will add the table to the model and will create a new entity for it. This is the same way that the Entity Data Model Wizard works when you are creating new models.

    However, the Update Model Wizard does not allow you to specify changes to existing objects. For example, tables that were included in the model but have since been modified in the database. The wizard will automatically apply those changes. If you have added new columns to an existing table for which an entity exists in the model, those fields will come into the model and will be added to the entity automatically. Not all changes will affect the conceptual model, however. For example, if you change the spelling of a column name in the database, the wizard will not know to line it up with the existing entity property and instead will create a new property. In this case, you would need to remove the new property and modify the entity mappings so that the existing property points to the correct column.


    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Alex Liang Wednesday, October 20, 2010 5:25 AM
    Friday, October 15, 2010 6:11 AM
  • Hi Alex,

    thanks for reply. Actually, I would need at least the EF to write detected changes into Output window or some log file to indicate the change might be needed in conceptual model. I started a new project (we use database model first approach) and the model has been designed in version 1 and created but it is still evolving and there are lotsd of changes into it. Together with naming style and customization of table and column names in conceptual model I found EF model difficult to maintain. I played also with t4 customization but I ended up with the need of customization model before the edmx file (I will write new post on this topic).

    eXavier

     

    • Marked as answer by Alex Liang Wednesday, October 20, 2010 5:26 AM
    Tuesday, October 19, 2010 12:13 PM

All replies

  • Hi eXavier,

    You can use the wizard to add objects that were created in the database after you originally built the model. For example, if a new table has been added to the database, the Update Model Wizard will discover that the table is not already listed in the Store Schema Definition Layer (SSDL) of the model and will display it in the Add page of the wizard. If you select this new table, the wizard will add the table to the model and will create a new entity for it. This is the same way that the Entity Data Model Wizard works when you are creating new models.

    However, the Update Model Wizard does not allow you to specify changes to existing objects. For example, tables that were included in the model but have since been modified in the database. The wizard will automatically apply those changes. If you have added new columns to an existing table for which an entity exists in the model, those fields will come into the model and will be added to the entity automatically. Not all changes will affect the conceptual model, however. For example, if you change the spelling of a column name in the database, the wizard will not know to line it up with the existing entity property and instead will create a new property. In this case, you would need to remove the new property and modify the entity mappings so that the existing property points to the correct column.


    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Alex Liang Wednesday, October 20, 2010 5:25 AM
    Friday, October 15, 2010 6:11 AM
  • Hi eXavier,

    I am writting to follow up the post. Does the above suggestion work ?

    Please feel free to let me know if you need help.

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, October 19, 2010 9:05 AM
  • Hi Alex,

    thanks for reply. Actually, I would need at least the EF to write detected changes into Output window or some log file to indicate the change might be needed in conceptual model. I started a new project (we use database model first approach) and the model has been designed in version 1 and created but it is still evolving and there are lotsd of changes into it. Together with naming style and customization of table and column names in conceptual model I found EF model difficult to maintain. I played also with t4 customization but I ended up with the need of customization model before the edmx file (I will write new post on this topic).

    eXavier

     

    • Marked as answer by Alex Liang Wednesday, October 20, 2010 5:26 AM
    Tuesday, October 19, 2010 12:13 PM
  • On 10/19/2010 7:13 AM, eXavier_777 wrote:
    > Hi Alex,
    >
    > thanks for reply. Actually, I would need at least the EF to write
    > detected changes into Output window or some log file to indicate the
    > change might be needed in conceptual model. I started a new project (we
    > use database model first approach) and the model has been designed in
    > version 1 and created but it is still evolving and there are lotsd of
    > changes into it. Together with naming style and customization of table
    > and column names in conceptual model I found EF model difficult to
    > maintain. I played also with t4 customization but I ended up with the
    > need of customization model before the edmx file (I will write new post
    > on this topic).
    >
    > eXavier
    >
     
    I always cringed when having to go back to the model and update it. It
    was painful. :)
     
    Tuesday, October 19, 2010 1:26 PM
  • Actually, I would need at least the EF to write detected changes into Output window or some log file to indicate the change might be needed in conceptual model.


    Take a look at http://huagati.blogspot.com/2010/08/using-model-comparer-to-generate.html

     


     

       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Rule based class and property naming, Compare and Sync model <=> DB, Sync SSDL <=> CSDL (EF4)
     huagati.com/L2SProfiler - Query profiler for Linq-to-SQL and Entity Framework v4
    Wednesday, October 20, 2010 12:48 AM