Skip to main content
.NET 8.0+

MapInheritanceAttribute Class

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

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.2.dll

Declaration

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
public sealed class MapInheritanceAttribute :
    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.

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 = "";

}

Inheritance

Object
Attribute
MapInheritanceAttribute
See Also