Spiderly LogoSPIDERLY
PlaygroundFAQDocs
PlaygroundFAQDocs
    • Getting Started
    • Entity
      • Add New Entity
      • Entity Validation
      • Entity Authorization
    • Customize UI
    • Translate Spiderly App
    • Attributes

Entity Validation
With Spiderly Attributes

Spiderly simplifies validation across your application by allowing you to annotate your entity classes with attributes.

Validation attributes fall into two categories:
  • Spiderly custom validation attributes
  • EF Core attributes from System.ComponentModel.DataAnnotations

Validation attributes are used to:
  • Automatically generate backend (DTO-level) validation.
  • Automatically generate frontend form validation rules.
  • Leave database validation to EF Core.

Behavior Based on Attribute Type:
  • EF Core attributes will result in database schema changes. When you use them, remember to run Add-Migration and Update-Database.
  • Spiderly backend validation attributes require rebuilding the backend to take effect.

Table of Contents

  • CustomValidatorAttribute
  • GreaterThanOrEqualToAttribute
  • PrecisionAttribute
  • RangeAttribute
  • RequiredAttribute
  • StringLengthAttribute

CustomValidatorAttribute

Usage

Defines custom validation rules for the decorated property or class (can be used on DTOs as well as entities).
Supports chaining of multiple rules using dot notation, e.g., EmailAddress().Length(5, 50).

Examples:


        

GreaterThanOrEqualToAttribute

Usage

Validates that a numeric property value is greater than or equal to a specified number. This attribute provides both server-side and client-side validation.

Example:


        

PrecisionAttribute

Usage

Specifies the precision and scale for a decimal property.
Useful for controlling how many digits are stored in total (precision) and how many of them are after the decimal point (scale).

ℹ️ Applies to the server-side, client-side validation and affects the EF Core model and will generate corresponding SQL column definition.

Example:


        

RangeAttribute

Usage

Validates that a numeric value falls within a specified inclusive range.

ℹ️ Applies to the server-side, client-side validation and affects the EF Core model and will generate corresponding SQL column definition.

Example:


        

RequiredAttribute

Usage

Specifies that a value must be provided for the decorated property, enforcing non-null values.

ℹ️ Applies to the server-side, client-side validation and affects the EF Core model and will generate corresponding SQL column definition.

Example:


        

StringLengthAttribute

Usage

Specifies the minimum and/or maximum length for a string property.

ℹ️ Applies to the server-side, client-side validation and affects the EF Core model and will generate corresponding SQL column definition.

Best Practice

💡 Always apply StringLength to string properties. If omitted, EF Core will map them to NVARCHAR(MAX) by default, which can negatively impact performance.

Example: