Le annotazioni sono degli attributi che possono essere applicati ad una entità o alle sue proprietà.

Le annotations hanno tre proprietà:

  • name: indica il nome del template (è possibile omettere l’estensione).
  • namespace: indica l’url su cui è presente il template (omettere il nome del template).
  • value: indica il valore dell’attributo (opzionale).

Nell’esempio sottostante, il template verrà scaricato dall’url https://schemacodearchitects.blob.core.windows.net/templates/entityfwk/minLength.ejs

entities:
  - name: Category
    description: The product category
    useRepository: true
    repositoryName: Category
    fields:
      - name: name
        type: string
        description: The name of the category
        annotations:
          - name: minLength
            namespace: https://schemacodearchitects.blob.core.windows.net/templates/entityfwk/
            value: 5

Questo andrà a generare una classe Category. La classe conterrà una proprietà Name alla quale sarà applicato l’attributo MinLength contenente il valore specificato.

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Ca.ShoppingCart.Store.Domain.Model
{
  /// <summary>
  /// The product category
  /// </summary>
  public partial class Category : EntityBase
  {
    /// <summary>
    /// The name of the category
    /// </summary>
    [MinLength(5)]
    public string Name
    {
      get;
      set;
    }
  }
}

MinLength
[MinLength(5)] Può essere applicato ad una proprietà per specificare la lunghezza minima della stringa consentita nella colonna corrispondente nel database. Per ulteriori informazioni fare riferimento alla documentazione ufficiale.

Per generare questa annotazione

annotations:
  - name: minLength
    namespace: https://schemacodearchitects.blob.core.windows.net/templates/entityfwk/
    value: 5