Repository navigation
Expo Value Rules
Comparison rules check a property against a constant. Enum rules reject values that the enum does not define. Combine rules when an operation needs a bounded range.
// CourseCapacity.cs
[Expo]
public sealed partial class CourseCapacity
{
[IsGreaterThanOrEqualTo(1, "A course needs at least one place.")]
[IsLessThanOrEqualTo(200)]
public int Capacity { get; init; }
[IsNotEqualTo("DRAFT", "Choose a published course code.")]
public string? CourseCode { get; init; }
}Capacity must be between 1 and 200 inclusive. CourseCode fails when it equals DRAFT; the equality rule allows null here because it differs from that constant.
| Rule | Required comparison |
|---|---|
[IsGreaterThan(value)] |
Property is greater than the constant |
[IsGreaterThanOrEqualTo(value)] |
Property is greater than or equal to the constant |
[IsLessThan(value)] |
Property is less than the constant |
[IsLessThanOrEqualTo(value)] |
Property is less than or equal to the constant |
[IsEqualTo(value)] |
Property equals the constant |
[IsNotEqualTo(value)] |
Property differs from the constant |
Ordering uses Comparer<T>.Default; equality uses EqualityComparer<T>.Default. The constant must be compatible with the property's type and valid as a C# attribute argument. Nullable values follow those comparers' semantics. Add an explicit presence rule when the application requires a value.
For a range relative to another property, use Property comparisons.
// CourseStatus.cs
public enum CourseStatus
{
Draft,
Published,
Closed
}// CoursePublication.cs
[Expo]
public sealed partial class CoursePublication
{
[EnumIsDefined("Choose a known course status.")]
public CourseStatus Status { get; init; }
}Casting an arbitrary integer to an enum does not guarantee a declared value. [EnumIsDefined] checks it with Enum.IsDefined. For nullable enums, null passes; add [IsRequired] if needed. For flags enums, a combination passes only when that exact combined value is declared.
Comparison and enum rules also apply to individual collection items. See Collections.
- Home
- Getting started
-
Package guides
- Partie
- Expo
-
Mise
- Database setup
- Table mappings
- Aliases
- Relationships
- Result rows
- SQL interpolation
- Queries
- Filtering
- Joins
- Aggregation
- Paging and ordering
- Subqueries
- Set operations
- Common table expressions
- Readers
- Streaming
- Writers
- Inserts
- Updates
- Deletes
- Returned rows
- Custom SQL and procedures
- Transactions
- Resource lifetimes
- Database dialects
- Diagnostics
- Integrations
- Recipes
- Reference
- Troubleshooting
- Development