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

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

XPO中的继承

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、将各类映射至各自的单表中

XPO中的继承 

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

 

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

 

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

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

相关文章:

  • 2021-03-31
  • 2021-05-26
  • 2021-07-07
  • 2022-01-24
  • 2021-09-18
  • 2021-05-03
  • 2021-12-05
猜你喜欢
  • 2021-07-05
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-01-06
相关资源
相似解决方案