XPO的继承类的持久化,简单说来有2种方式:

1、将继承关系映射到一张单表:

using DevExpress.Xpo;


public class Person : XPObject {

    public string Name = "";

}


[MapInheritance(MapInheritanceType.ParentTable)]

class Customer : Person {

    public string Preferences = "";

}


[MapInheritance(MapInheritanceType.ParentTable)]

public class Employee : Person {

    public int Salary = 1000;

}


[MapInheritance(MapInheritanceType.ParentTable)]

public class Executive : Employee {

    public int Bonus = 100;

}

 

要采用这种方式只需要在属性上添加一个属性[MapInheritance(MapInheritanceType.ParentTable)]即可。

 

优点:因为所有的东西都在一起,修改方便,速度快,避免Join操作。 

缺点:很明显,将浪费大量的空间。

 

 2、将各类映射至各自的单表中

 

代码不贴了,就是把属性改为MapInheritanceType.OwnTable

 

注意XPO必须把基类也保存成一张单独的表,拿图中例子来说,没有办法让XPO在3个子类表中都增加一个Name字段而省略掉Person表。 

 

优点:不像上一种方式那样浪费空间。如果这也算优点的话。

缺点:逃不掉Join操作,会带来性能损失。 

posted on 2010-02-03 15:13  Elvin Chen  阅读(668)  评论(0编辑  收藏  举报