Back to Devexpress

MapInheritanceAttribute Class

xpo-devexpress-dot-xpo-fbbc4acf.md

latest4.5 KB
Original Source

MapInheritanceAttribute Class

Specifies the type of object-relational inheritance mapping for the class.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
public sealed class MapInheritanceAttribute :
    Attribute
vb
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Interface, Inherited:=False)>
Public NotInheritable Class MapInheritanceAttribute
    Inherits Attribute

Remarks

XPO supports inheritance and polymorphism of persistent objects. By default, XPO stores descendant-specific persistent properties in separate tables and it automatically joins tables to retrieve object data. To store descendant-specific properties in a base class table, the MapInheritanceAttribute attribute must be applied to the descendant class. Its MapInheritanceAttribute.MapType property must be set to the MapInheritanceType.ParentTable value.

If the MapInheritanceAttribute.MapType property is set to the MapInheritanceType.OwnTable value or if this attribute isn’t applied, a new table is created to store the persistent data of descendant objects.

In the example below the MapInheritanceAttribute attribute with its MapInheritanceAttribute.MapType property set to the MapInheritanceType.ParentTable value is applied to the TestContact class. As a result, all persistent fields of TestContact objects will be saved to the table where the persistent data of TestEntity objects is stored.

csharp
public class TestEntity: XPObject {
   public TestEntity(Session session) : base(session) { }
   public string Name {
       get { return fName; }
       set { SetPropertyValue(nameof(Name), ref fName, value); }
   }
   string fName = "";

}

[MapInheritance(MapInheritanceType.ParentTable)]
public class TestContact: TestEntity {
    public TestContact(Session session) : base(session) { }
    public string FirstName {
        get { return fFirstName; }
        set { SetPropertyValue(nameof(FirstName), ref fFirstName, value); }
    }
    string fFirstName = "";

    public string LastName {
        get { return fLastName; }
        set { SetPropertyValue(nameof(LastName), ref fLastName, value); }
    }
    string fLastName = "";

}
vb
Class TestEntity
   Inherits XPObject

   Public Sub New(ByVal _session As Session)
      MyBase.New(_session)
   End Sub

   Public Property Name() As String
       Get
           Return fName
       End Get
       Set(ByVal value as String)
           SetPropertyValue(NameOf(Name), fName, value)
       End Set
   End Property
   Private fName As String = ""

End Class 

<MapInheritance(MapInheritanceType.ParentTable)> _
Class TestContact
   Inherits TestEntity

   Public Sub New(ByVal _session As Session)
      MyBase.New(_session)
   End Sub

   Public Property FirstName() As String
       Get
           Return fFirstName
       End Get
       Set(ByVal value as String)
           SetPropertyValue(NameOf(FirstName), fFirstName, value)
       End Set
   End Property
   Private fFirstName As String = ""

   Public Property LastName() As String
       Get
           Return fLastName
       End Get
       Set(ByVal value as String)
           SetPropertyValue(NameOf(LastName), fLastName, value)
       End Set
   End Property
   Private fLastName As String = ""

End Class

Inheritance

Object Attribute MapInheritanceAttribute

See Also

MapInheritanceAttribute Members

How to: Change Inheritance Mapping

Built-In Attributes

DevExpress.Xpo Namespace