Entity Template

The template for the file used when adding new entities to a web API using the `add:entity` command.

Add Entity Template Properties

NameRequiredDescriptionDefault
EntitiesYesA list of entities to create database endpoints.None
AuthorizationSettingsNoThe authorization settings (e.g. policies) that are set for the entity.None
AddSwaggerCommentsNoDetermines whether or not Craftsman should scaffold out detailed swagger comments for each endpoint.false

Add Entity Template Examples

Basic Add Entity Example

The add entity template only needs the details for the new entity objects you want to add (one or more entities). You can find more details on the add entity command page.

AddSwaggerComments: true
Entities:
  - Name: Supplier
    Properties:
      - Name: SupplierId
        IsPrimaryKey: true
        Type: int
        CanFilter: true
        CanSort: true
      - Name: Name
        Type: string
        CanFilter: true
        CanSort: true
      - Name: EmployeeCount
        Type: int?
        CanFilter: true
        CanSort: true
      - Name: CreationDate
        Type: datetime?
        CanFilter: true
        CanSort: true
      - Name: SupplierType
        Type: int?
        CanFilter: true
        CanSort: true
  - Name: Material
    Properties:
      - Name: MaterialId
        IsPrimaryKey: true
        Type: int
        CanFilter: true
        CanSort: true
      - Name: Name
        Type: string
        CanFilter: true
        CanSort: true

Add Entity Example With Authorization Settings

If you've configured your app to use authorization, you can add authorization settings as well.

AddSwaggerComments: true
Entities:
  - Name: Supplier
    Properties:
      - Name: SupplierId
        IsPrimaryKey: true
        Type: int
        CanFilter: true
        CanSort: true
      - Name: Name
        Type: string
        CanFilter: true
        CanSort: true
      - Name: EmployeeCount
        Type: int?
        CanFilter: true
        CanSort: true
      - Name: CreationDate
        Type: datetime?
        CanFilter: true
        CanSort: true
      - Name: SupplierType
        Type: int?
        CanFilter: true
        CanSort: true
  - Name: Material
    Properties:
      - Name: MaterialId
        IsPrimaryKey: true
        Type: int
        CanFilter: true
        CanSort: true
      - Name: Name
        Type: string
        CanFilter: true
        CanSort: true
AuthorizationSettings:
  Policies:
    - Name: CanReadSuppliers
      PolicyType: scope
      PolicyValue: suppliers.read
      EndpointEntities:
        - EntityName: Supplier
          RestrictedEndpoints:
            - GetList
            - GetRecord
    - Name: CanAddSuppliers
      PolicyType: scope
      PolicyValue: suppliers.add
      EndpointEntities:
        - EntityName: Supplier
          RestrictedEndpoints:
            - AddRecord
    - Name: CanDeleteSuppliers
      PolicyType: scope
      PolicyValue: suppliers.delete
      EndpointEntities:
        - EntityName: Supplier
          RestrictedEndpoints:
            - DeleteRecord
    - Name: CanUpdateSuppliers
      PolicyType: scope
      PolicyValue: suppliers.update
      EndpointEntities:
        - EntityName: Supplier
          RestrictedEndpoints:
            - UpdateRecord
            - UpdatePartial
    - Name: CanAddMaterials
      PolicyType: scope
      PolicyValue: materials.add
      EndpointEntities:
        - EntityName: Material
          RestrictedEndpoints:
            - AddRecord
    - Name: CanDeleteMaterials
      PolicyType: scope
      PolicyValue: materials.delete
      EndpointEntities:
        - EntityName: Material
          RestrictedEndpoints:
            - DeleteRecord
    - Name: CanUpdateMaterials
      PolicyType: scope
      PolicyValue: materials.update
      EndpointEntities:
        - EntityName: Material
          RestrictedEndpoints:
            - UpdateRecord
            - UpdatePartial