Hi,

I want to rename a Field of a Structure, but I can't find the right upgrader hint to do it. I have tried the following hint :

hints.Add(new RenameFieldHint(typeof(MyEntity), "MyStructure.Name", "MyStructure.NewName"));

The hint is accepted by validateRenameFieldHints method and goes to the upgrader phase where i have the following exception (note the hint is not listed in Schema hints but the 'new RenameFieldHint' has been executed, I have double checked that by changing the name of a the 2nd argument in call of RenameFieldHint to a random property name and i do get the validateRenameFieldHints exception):

Xtensive.Orm.SchemaSynchronizationException: 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/MyEntity/Columns/MyStructure.Name
Schema hints:

Schema difference:
  "./" != "./" (NodeDifference): Unknown
    +Tables: "./Tables (4)" != "./Tables (4)" (NodeCollectionDifference): 1 change(s)
      "./Tables/MyEntity" != "./Tables/MyEntity" (NodeDifference): Unknown
        +Columns: "./Tables/MyEntity/Columns (2)" != "./Tables/MyEntity/Columns (2)" (NodeCollectionDifference): 2 change(s)
          "./Tables/MyEntity/Columns/MyStructure.Name" != "" (NodeDifference): Removed
            +Type: "Type: String?, Length: 4000, Native type: VarChar(4000)" != "" (ValueDifference): values differ
          "" != "./Tables/MyEntity/Columns/MyStructure.NewName" (NodeDifference): Created
            +Type: "" != "Type: String?, Length: 4000, Native type: VarChar(4000)" (ValueDifference): values differ
   à Xtensive.Orm.Upgrade.UpgradingDomainBuilder.SynchronizeSchema(Domain domain, SchemaUpgrader upgrader, SchemaExtractor extractor, SchemaUpgradeMode schemaUpgradeMode)

Sample used:

  public class MyStructure : Structure
  {
    [Field]
    public string NewName { get; set; }
  }

  [Serializable]
  [HierarchyRoot]
  public class MyEntity : Entity
  {
    [Field, Key]
    public int Id { get; private set; }

    [Field]
    public MyStructure MyStructure { get; set; }

    public MyEntity(Session session): base(session)
    {
    }
  }

Is this possible to do ? What would be the right syntax ? Shall i upgrade the column names in raw sql ?

Benoit

asked Nov 06 '14 at 10:42

Benoit%20Nesme's gravatar image

Benoit Nesme
13111316

edited Nov 06 '14 at 10:45


2 Answers:

Hi Benoit Nesme.

Try to use this code:


hints.Add(new RenameFieldHint(typeof (MyStructure), "Name", "NewName"));

answered Nov 07 '14 at 04:42

Alexey%20Kulakov's gravatar image

Alexey Kulakov
45215

edited Nov 07 '14 at 04:42

Hi Alexey,

Thanks for your reply. Here what I get when using "Name", "NewName".

    System.InvalidOperationException: Field 'DO_Tests.Model.MyEntity.Name' is not found.
   à Xtensive.Orm.Upgrade.HintGenerator.ValidateRenameFieldHints(IEnumerable`1 hints)
   à Xtensive.Orm.Upgrade.HintGenerator.ValidateHints(NativeTypeClassifier`1 hints)
   à Xtensive.Orm.Upgrade.HintGenerator.Run()
   à Xtensive.Orm.Upgrade.UpgradingDomainBuilder.BuildSchemaHints(StorageModel extractedSchema)
   à Xtensive.Orm.Upgrade.UpgradingDomainBuilder.GetSchemaHints(StorageModel extractedSchema, StorageModel targetSchema)
   à Xtensive.Orm.Upgrade.UpgradingDomainBuilder.SynchronizeSchema(Domain domain, SchemaUpgrader upgrader, SchemaExtractor extractor, SchemaUpgradeMode schemaUpgradeMode)

answered Nov 07 '14 at 04:45

Benoit%20Nesme's gravatar image

Benoit Nesme
13111316

It means that your old model have type MyEntity but this type haven't "Name" field. Do you sure that field is exists? Maybe you have a misprint. Because it works correctly.

(Nov 10 '14 at 02:53) Alexey Kulakov Alexey%20Kulakov's gravatar image

Alexey, I just tried what you proposed : hints.Add(new RenameFieldHint(typeof (MyStructure), "Name", "NewName")); But this doesn't work and it's not surprising since in my model I don't have a Field named 'Name' : I have a Field named MyStructure and i want to rename one field of MyStructure (MyStructure is a Structure). Could you please check what is the right UpgraderHint to rename a Field in a Structure ? I have a made a sample project using DO5.0.3 available here : http://demo.ovh.eu/a68aeb8eb5702a663295ecb5d9f07ca9/ Please note: we need a fix for DO4.6

(Nov 14 '14 at 04:44) Benoit Nesme Benoit%20Nesme's gravatar image

I've created simple project which demonstrates that renaming works fine. I used same DO version - 4.6.8. http://demo.ovh.eu/en/11c15723305fea0f1748c3c54bc89d8b/

(Nov 17 '14 at 04:27) Alexey Kulakov Alexey%20Kulakov's gravatar image

Alexey, I had misread your upgradehint where you wrote typeof(MyStructure) and I tested with typeof(MyEntity). So it works fine ! Thanks!

(Nov 17 '14 at 04:56) Benoit Nesme Benoit%20Nesme'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