Have I broken it?

3 posts, 1 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 20 Dec 2010 Link to this post

    Being a sucker for punishment, I've decided to have another go with OA.

    I've got a new project and have opted to add a domain model from an existing DB in which I have added a single table.

    Went through all the steps and got my EntityDiagram.

    All OK so far.

    Now, my table has a column named 'postaladdress' which OA mapped to a property called 'Postaladdress'.

    I went to the DB and changed the name of the column to 'postalAddress' (note the change of capitalization).

    I went to the model in VS and, in the Model Explorer, I right-clicked the top-level of the tree and opted to 'Update From Database'. In the resulting dialog, I clicked on 'Apply All' then on 'Finish'.

    The model updates, but instead of simply renaming my 'PostalAddress' property to 'PostalAddress', the model ADDS a new property called 'PostalAddress'. The old 'Postaladdress' property is still in the model!

    Surely, that can't be right!

    There is, I've discovered, a workaround and that is, in the Schema Explorer, remove and then remap the persistent class.

    --
    Stuart 
  2. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 21 Dec 2010 Link to this post

    Hi Stuart Hemming,

    In fact this is the expected behavior. When a column (or table) is renamed in the database we cannot really be sure that this has happened, the database gives no information about such changes. However, by comparing the schema before and after we see that one of the old columns is missing and new one has been added. The default action we would perform in this case is add a property to map the new column. The old property will not be deleted in order to preserve the changes you might have done there, but it will be left unmapped. You can see that the old property is not associated with a column in the Mapping Details Editor.

    If you would like to use the old property with the renamed column you can use the Details Editor to unmap the newly generated property and map the column to the old one. You can then remove the new property (just delete it from the diagram) and rename the old one if needed.

    There is also another way to update the model when something has been renamed in the database. If you have not already run the Update From Database wizard, open it and follow the instructions in this article, under the Modify section. This way you will be able to merge the Add and Remove actions into a single Modify action and update the old column instead of adding new one.
    Hope that helps.

    All the best,
    Alexander
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  3. DevCraft banner
  4. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 21 Dec 2010 Link to this post

    Alexander,

    Thanks.

    -- 
    Stuart
Back to Top