Back to Devexpress

ExpandObjectMembersAttribute Class

expressappframework-devexpress-dot-persistent-dot-base-7d818005.md

latest5.1 KB
Original Source

ExpandObjectMembersAttribute Class

Specifies whether the target reference property is displayed via several Property Editors representing the referenced object’s properties or via a single Lookup or Object Property Editor.

Namespace : DevExpress.Persistent.Base

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface, Inherited = true)]
public class ExpandObjectMembersAttribute :
    Attribute
vb
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Interface, Inherited:=True)>
Public Class ExpandObjectMembersAttribute
    Inherits Attribute

Remarks

XAF can visualize a reference property in two ways. The first way is to display a non-aggregated property via a Lookup Property Editor to allow you to choose the property value by selecting one of the existing objects of the corresponding type; aggregated properties are displayed via an Object Property Editor. The second way is to display several Property Editors representing the referenced object’s properties. This way you can customize the referenced object’s property values, but you cannot change the reference property value by choosing another object since the Property Editor for the reference property is not displayed.

By default, non-aggregated reference properties are visualized via a Lookup Property Editor. Aggregated reference properties are visualized via several Property Editors representing the referenced object’s properties. When the default behavior does not suit your needs, decorate a reference property with ExpandObjectMembersAttribute. Specify how the property must be displayed via the expandingMode parameter in the attribute constructor. There are four possible parameter values. The following example demonstrates their use. Suppose you have the Contact class that exposes the Address reference property of the Address type.

csharp
[DefaultClassOptions]
public class Contact : BaseObject {
    public virtual string Name { get; set; }
    public virtual Address Address { get; set; }
}

[DefaultClassOptions, DefaultProperty(nameof(StreetAddress))]
public class Address : BaseObject {
    public virtual string StreetAddress { get; set; }
    public virtual string Phone { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
csharp
[DefaultClassOptions]
public class Contact : BaseObject {
    public Contact(Session session) : base(session) { }
    public string Name {
        get { return GetPropertyValue<string>(nameof(Name)); }
        set { SetPropertyValue<string>(nameof(Name), value); }
    }
    public Address Address {
        get { return GetPropertyValue<Address>(nameof(Address)); }
        set { SetPropertyValue<Address>(nameof(Address), value); }
    }
}
[DefaultClassOptions, DefaultProperty(nameof(StreetAddress))]
public class Address : BaseObject {
    public Address(Session session) : base(session) { }
    public string StreetAddress {
        get { return GetPropertyValue<string>(nameof(StreetAddress)); }
        set { SetPropertyValue<string>(nameof(StreetAddress), value); }
    }
    public string Phone {
        get { return GetPropertyValue<string>(nameof(Phone)); }
        set { SetPropertyValue<string>(nameof(Phone), value); }
    }
}

If you decorate the Contact.Address property with ExpandObjectMembersAttribute , here is how Contact Views will be affected.

Inheritance

Object Attribute ExpandObjectMembersAttribute

See Also

ExpandObjectMembersAttribute Members

ExpandObjectMembers

View Items and Property Editors

DevExpress.Persistent.Base Namespace