If I change a field name in a class, DO deletes all the data in that column. This is not standard SQL Server behavior.

asked Jan 29 '14 at 00:29

Nomad99's gravatar image

Nomad99
7447


3 Answers:

Hello,

likely you're using DomainUpgradeMode.Perform

In this mode DataObjects.Net will upgrade any current database schema to match your model types.

There is no magic way of guessing what changes were made to the model: column was renamed or column was removed and another column was added. That's why you get this column removed.

If you want to actually rename the column and preserve data you'll need to instruct DataObjects.Net to do so by providing upgrade hints. Various model change scenarios are covered in our manual.

When using DomainUpgradeMode.PerformSafely DataObjects.Net will refuse to do any destructive action unless explicitly allowed.

answered Jan 29 '14 at 08:39

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

PerformSafely won't even change a column name so I am not sure what it is good for...

Extracted schema is not equal to the target schema. Details: Schema comparison result: NotEqual Has unsafe actions: true Has column type changes: false Compatible in ValidateLegacy mode: unknown

Unsafe actions: RemoveNode, Path=Tables/Child/Columns/C1

You should be able to rename columns without DO remove them. I understand that could break a relationship but this should be the default not removing the column. RemoveNode, Path=Tables/Child/Columns/C2 Schema hints:

answered Jan 29 '14 at 10:19

Nomad99's gravatar image

Nomad99
7447

edited Jan 29 '14 at 10:29

Hi

What you need is to write UpgradeHandler like the following:

public class Upgrader : UpgradeHandler
{
  protected override void AddUpgradeHints(Xtensive.Collections.ISet<UpgradeHint> hints)
  {
    hints.Add(new RenameFieldHint(typeof (Person), "Name", "FullName"));
  }
}

This must solve your issue. Having explanation what happend with model DataObjects won't fail with error in DomainUpgradeMode.PerformSafely mode.

answered Jan 30 '14 at 00:29

Alex%20Ustinov's gravatar image

Alex Ustinov
2484

I know I can do this but the point I trying to make is that I shouldn't have to. The default behavior of DO should be NOT to remove and recreate the column. Why would do you feel you absolutely have to do this?

(Jan 30 '14 at 01:05) Nomad99 Nomad99's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA