Confinity Documentation
  • Latest Version
  • Latest Version
  • Getting Started

    • Introduction
    • Core Concepts
    • Create an Application
    • Glossary
  • Essentials

    • Authentication & SSO
    • Breaking Changes
    • Roslyn Source Analyzers
    • Changelog
    • ConfinityContent
    • ConfinitySelectable
    • Confinity Schedules
    • Data Seeding
    • Development guidelines [WIP]
    • Entity App
    • Entity Form
    • Entity Permissions
    • Frontend Configuration
    • Images
    • Known Issues
    • Localization
    • Migrations
    • Modules [WIP]
    • On-Site Editing
    • Settings
    • Cascade Delete
    • Replication
    • Infrastructure
  • Modules

    • Analytics Module
    • Assets Module
    • Blog Module
    • Cookie Consent Module
    • Forms Module
    • Friendly Captcha (Forms Module )
    • GeoIP Module
    • Htmx
    • Mail Module
    • Mailing Module
    • MediaPlayer Module
    • GoogleMyBusiness Module
    • OpenTelemetry Module
    • Pages Module [WIP]
    • Pattern Library Module
    • SIX Saferpay (worldline) Module
    • Products Module
    • Search Module
    • Wizard Module
  • Guides

    • Create a Custom Entity App Form Element
    • Date and Time
    • Entity Change Listener
    • File Upload / Temp File
    • HTTP security headers
    • conventions [WIP]
    • How to use Confinity with nginx
    • Notifications
    • Nullability
    • Rename Entity
    • Schedules
    • Useful snippets
    • Content Localization
  • Design Guidelines

    • Introduction
    • Page Components
    • Forms Module

ConfinitySelectable

Instead of using Enumeration types properties on your entities, consider using ConfinitySelectable. It is designed to replace enums in your Entity Apps. It is similar to an enum, but is optimized for stability and the use with Confinity.

ConfinitySelectable is a base class with the properties Id, Label and SortIndex (optionally). Stored to the database is only the Id. The Label is used in the entity app. Confinity will search for static fields to find all constants of your ConfinitySelectable.

Define a ConfinitySelectable

To define a ConfinitySelectable you just create a new class which inherits from ConfinitySelectable. For every constant, create a public static field as in the following example.


public class ShirtSize : ConfinitySelectable
{
    public static readonly ShirtSize Small = new("small", "Small");
    public static readonly ShirtSize Medium = new("medium", "Medium");
    public static readonly ShirtSize Large = new("large", "Large");

    public ShirtSize(string id, string? label = null, int sortIndex = 0)
        : base(id, label, sortIndex)
    {
    }
}

The ConfinitySelectable can be extended with additional properties or fields.


public class Color : ConfinitySelectable
{
    private readonly string _hex;
    public static readonly Color Red = new("small", "Small", " #FF0000");
    public static readonly Color Green = new("medium", "Medium", "#00FF00");
    public static readonly Color Blue = new("large", "Large", "#0000FF");

    public Color(string id, string? label = null, int sortIndex = 0)
        : base(id, label, sortIndex)
    {
        _hex = "";
    }

    private Color(string id, string label, string hex)
        : base(id, label, 0)
    {
        _hex = hex;
    }
}

Restrictions

Every ConfinitySelectable must have a constructor for id, label and sortIndex.

Warning

The parameters must not be changed from id, label and sortIndex.

Comparison to enum

  • Advantages
    • No mapping(s) for labels and other data in the entity app
    • Less error prone / easier to handle instead of always remembering that a enum is a number.
    • Backwards compatible (unknown values are still read, the author can update them in the entity app and a developer can fix them by using a ef core migration)
  • Disadvantages
    • Working with enums is slightly faster

Recommendations

For tables with many rows, use short id and set the field length on the column.

Prev
ConfinityContent
Next
Confinity Schedules