Add RemoveTypeHint for type, but don't delete this type

Result: All data for entity will be removed

Recreate:

using System;

using Xtensive.Orm;
using Xtensive.Orm.Configuration;

public static class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");
        dc.Types.Register(typeof(Source));
        dc.UpgradeMode = DomainUpgradeMode.Recreate;

        using (var domain = Domain.Build(dc))
        {
            using (var s = domain.OpenSession())
            using (s.Activate())
            using (var t = s.OpenTransaction())
            {
                new Source(Guid.NewGuid()) { Name = "Test" };
                t.Complete();
            }
        }
    }
}

[HierarchyRoot]
public class Source : Entity
{
    public Source(Guid id)
        : base(id)
    {
    }

    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field]
    public string Name { get; set; }
}

Perform:

using System;
using System.Linq;

using NUnit.Framework;

using Xtensive.Orm;
using Xtensive.Orm.Configuration;
using Xtensive.Orm.Upgrade;

public static class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");
        dc.Types.Register(typeof(Source));
        dc.Types.Register(typeof(Upgrader));
        dc.UpgradeMode = DomainUpgradeMode.PerformSafely;

        using (var domain = Domain.Build(dc))
        {
            using (var s = domain.OpenSession())
            using (s.Activate())
            using (var t = s.OpenTransaction())
            {
                Assert.Greater(s.Query.All<Source>().Count(), 0);
                Assert.AreEqual("Test", s.Query.All<Source>().First().Name);
            }
        }
    }
}

public class Upgrader : UpgradeHandler
{
    protected override void AddUpgradeHints(Xtensive.Collections.ISet<UpgradeHint> hints)
    {
        hints.Add(new RemoveTypeHint("TestDO.Source"));
    }
}

[HierarchyRoot]
public class Source : Entity
{
    public Source(Guid id)
        : base(id)
    {
    }

    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field]
    public string Name { get; set; }
}

asked Aug 29 '14 at 02:49

Anton%20Guschin's gravatar image

Anton Guschin
73223035


One Answer:

Hi Anton.

You tell DO: "Remove this type from database. I'll take care about risks." And DO remove table "Source" and after that creates new table with same name in agree with new model.

Creation of new table is safe operation and removing of table with data is unsafe operation and you allow DO to remove table when you create hint.

Tell me what exactly you want to do and I'll try to help you.

answered Aug 29 '14 at 07:41

Alexey%20Kulakov's gravatar image

Alexey Kulakov
45215

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