Skip to content

Attributes

Coalesce provides a number of C# attributes that can be used to decorate your model classes and their properties to customize behavior, appearance, security, and more. Coalesce also supports a number of annotations from System.ComponentModel.DataAnnotations.

Coalesce Attributes

Browse the list in the sidebar to learn about the attributes that Coalesce provides for decorating your models.

ComponentModel Attributes

Coalesce also supports a number of the built-in System.ComponentModel.DataAnnotations attributes and will use these to shape the generated code.

[Display]

System.ComponentModel.DataAnnotations.DisplayAttribute

The displayed name and description of a property, as well as the order in which it appears in generated views, can be set via the [Display] attribute. By default, properties will be displayed in the order in which they are defined in their class.

[DisplayName]

System.ComponentModel.DisplayNameAttribute

The displayed name of a property can also be set via the [DisplayName] attribute.

[Description]

System.ComponentModel.DescriptionAttribute

The description of a type or member, such as a class, property, method, or parameter.

[Required]

System.ComponentModel.DataAnnotations.RequiredAttribute

Properties with [Required] will generate client validation and server validation rules.

[Range]

System.ComponentModel.DataAnnotations.RangeAttribute

Properties with [Range] will generate client validation and server validation rules.

[MinLength]

System.ComponentModel.DataAnnotations.MinLengthAttribute

Properties with [MinLength] will generate client validation and server validation rules.

[MaxLength]

System.ComponentModel.DataAnnotations.MaxLengthAttribute

Properties with [MaxLength] will generate client validation and server validation rules.

[DataType]

System.ComponentModel.DataAnnotations.DataTypeAttribute

Some values of DataType when provided to DataTypeAttribute on a string property will alter the behavior of the Vue Components. See c-display and c-input for details.

[ForeignKey]

System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute

Normally, Coalesce figures out which properties are foreign keys, but if you don't use standard EF naming conventions then you'll need to annotate with [ForeignKey] to help out both EF and Coalesce. See the Entity Framework Relationships documentation for more.

[InverseProperty]

System.ComponentModel.DataAnnotations.Schema.InversePropertyAttribute

Sometimes, Coalesce (and EF, too) can have trouble figuring out what the foreign key is supposed to be for a collection navigation property. See the Entity Framework Relationships documentation for details on how and why to use [InverseProperty].

[DatabaseGenerated]

System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedAttribute

Primary Keys with [DatabaseGenerated(DatabaseGeneratedOption.None)] will be settable on the client and will be appropriately handled by the Standard Behaviors on the server.

[NotMapped]

System.ComponentModel.DataAnnotations.Schema.NotMappedAttribute

Model properties that aren't mapped to the database should be marked with [NotMapped] so that Coalesce doesn't try to load them from the database when searching or carrying out the Default Loading Behavior.

[DefaultValue]

System.ComponentModel.DefaultValueAttribute

Properties with [DefaultValue] will receive the specified value when a new ViewModel is instantiated on the client. This enables scenarios like pre-filling a required property with a suggested value.


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.