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 Guschin
73●30●30●35