The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

How to: Work with Structures

  • 2 min to read

This example shows how to store and retrieve properties that are represented by structures and how to build query criteria based on them.

The Shape.Position property is represented by a Point struct type.

public struct Point {
    public int X;
    public int Y;
public class Shape: XPObject {
    public Shape(Session session) : base(session) { }
    public string Name = "";
    public Point Position;

By default, the property of a struct type (in our case this is the Position property) cannot be stored to the data store unless it is marked with the PersistentAttribute. In this tutorial, the 'X' struct member will be stored in the 'Abscissa' database column (its name is specified in the PersistentAttribute). The 'Y' struct member will be stored in a database column called 'LocationY'. This is the default name for this struct member. This name is automatically constructed from the name of a struct type property followed by the struct's member name.

Struct's members can be accessed as shown below.

session1 = new DevExpress.Xpo.Session();
// ...

Shape shape1 = new Shape(session1);
shape1.Name = "Ellipse";
shape1.Position.X = 1;
shape1.Position.Y = 2;

Struct members can also be used to construct query criteria for the collection. The following code demonstrates how to query the data store for Shapes with Position.X equal to 1.

XPCollection<Shape> xpCollection1 = 
    new XPCollection<Shape>(session1, CriteriaOperator.Parse("Position.X = 1"));