google-code-export / dataobjectsdotnet

Automatically exported from code.google.com/p/dataobjectsdotnet
0 stars 0 forks source link

Schema upgrade error with Nullable change #723

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
SourceSchema:

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

    [Field(Length = 100)]
    public string Text { get; set; }

}

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

    [Field(Length = 100)]
    public string Text { get; set; }

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

Create database (sqlserver) with this schema.

2. Change 
    [Field]
    public MyEntity MyEntity { get; set; }
to:
    [Field(Nullable = false)]
    public MyEntity MyEntity { get; set; }

3. Run application with upgradeMode="PerformSafely"

Xtensive.Storage.SchemaSynchronizationException was unhandled
  Message=Cannot upgrade schema safely (can't change type of column 'Tables/MyEntity2/Columns/MyEntity.Id').

This is wrong, becuse there are no modifications with data loss.

4. Create updateHandler:
public class Upgrader : UpgradeHandler
{
    protected override void AddUpgradeHints(Xtensive.Core.Collections.ISet<UpgradeHint> hints)
    {
/// here, also tried to use MyEntity.Id field
        hints.Add(new ChangeFieldTypeHint(typeof(MyEntity2), "MyEntity"));
        base.AddUpgradeHints(hints);
    }
}

same exception.

What is the expected output? 
Silent schema upgrade
What do you see instead?
Exceptions
What version of the product are you using? On what operating system?
DO 4.3 RC4

Original issue reported on code.google.com by kl.v...@gmail.com on 5 Jul 2010 at 10:46

GoogleCodeExporter commented 9 years ago

Original comment by alexis.k...@gmail.com on 6 Jul 2010 at 11:37

GoogleCodeExporter commented 9 years ago

Original comment by alexis.k...@gmail.com on 6 Jul 2010 at 11:38

GoogleCodeExporter commented 9 years ago

Original comment by alex.yakunin on 6 Jul 2010 at 5:56

GoogleCodeExporter commented 9 years ago

Original comment by alex.yakunin on 6 Jul 2010 at 6:52

GoogleCodeExporter commented 9 years ago
For now I din't recommend using non-nullable reference fields. They're fully 
supported only in Legacy mode. In other modes this is normally fully acceptable.

The issue will be resolved a bit later.

Original comment by alex.yakunin on 6 Jul 2010 at 6:53

GoogleCodeExporter commented 9 years ago
Done.

See issue 791, issue 790 and issue 743.

Original comment by alex.yakunin on 31 Aug 2010 at 2:39

GoogleCodeExporter commented 9 years ago

Original comment by alex.yakunin on 31 Aug 2010 at 2:39