First, I created Model v1 and fill it with some data:
public abstract class BaseType : Entity
{
[Field,Key]
public int Id { get; private set; }
[Field]
public string Text { get; set; }
}
[HierarchyRoot]
public class A1 : BaseType
{
[Field]
public DateTime Date { get; set; }
}
[HierarchyRoot]
public class A2 : BaseType
{
[Field]
public int Length { get; set; }
}
Then I move Hierarchy root attribute Up and use ConcreteTable InheritanceSchema:
[HierarchyRoot(InheritanceSchema.ConcreteTable)]
public abstract class BaseType : Entity
{
[Field,Key]
public int Id { get; private set; }
[Field]
public string Text { get; set; }
}
public class A1 : BaseType
{
[Field]
public DateTime Date { get; set; }
}
public class A2 : BaseType
{
[Field]
public int Length { get; set; }
}
Expected that my Data will be exist after safely update by PerformSafely.
Full example:
//[HierarchyRoot(InheritanceSchema.ConcreteTable)]
public abstract class BaseType : Entity
{
[Field,Key]
public int Id { get; private set; }
[Field]
public string Text { get; set; }
}
[HierarchyRoot]
public class A1 : BaseType
{
[Field]
public DateTime Date { get; set; }
}
[HierarchyRoot]
public class A2 : BaseType
{
[Field]
public int Length { get; set; }
}
class Program
{
private static void Main(string[] args)
{
var conf = new DomainConfiguration("sqlserver://localhost/DO40-Tests");
conf.UpgradeMode = DomainUpgradeMode.PerformSafely;
conf.Types.Register(typeof(A1));
conf.Types.Register(typeof(A2));
conf.Types.Register(typeof(BaseType));
using (var d1 = Domain.Build(conf))
{
using (var s = d1.OpenSession())
using (s.Activate())
{
using (var t = s.OpenTransaction())
{
var a1 = new A1() { Text = "A1", Date = DateTime.Now };
var a2 = new A2() { Text = "A2", Length = 123 };
t.Complete();
}
}
using (var s = d1.OpenSession())
using (s.Activate())
{
using (var t = s.OpenTransaction())
{
foreach (var item in Query.All<A1>())
{
Console.WriteLine(item);
}
t.Complete();
}
}
}
}
}
asked
Nov 10 '15 at 04:08
pil0t
207●57●57●63