Entities

Entities Required

An list of database entities in your project. These entities are added as dbsets to your database context, so they translate 1:1 to tables in your database.

Entity Properties

NameRequiredDescriptionDefault
NameYesThe name of the entityNone
PropertiesYesA list of properties assigned to your entity described in the entity properties section.None
PluralNoThe plural of the entity name, if needed (e.g. Cities would prevent Citys)Entity Name appended with an s
LambdaNoThe value to use in lambda expressions for this entity.First letter of the entity name.
TableNameNoThe name of the table in the database.Defaulted to the singular Name.
SchemaNoThe schema to use in the database.None, which will equate to dbo in SqlServer, public in Postgres, or mydb in MySQL

Properties

An list of properties that can be assigned to an entity.

NameRequiredDescriptionDefault
NameYesThe name of the propertyNone
TypeYesThe data type for the property. These are not case sensitive and they can be set to nullable with a trailing ?.None
IsPrimaryKeyYesWhen true, the property will be set as the primary key for the entity. For now, only one primary key is supported, with plans to add compound key support down the road.false
CanFilterNoWill set the property to be filterable in the API endpoint when set to true.false
CanSortNoWill set the property to be filterable in the API endpoint when set to true.false
IsRequiredNoWhen true, the property will be set as required in the database.false
true for primary key
ColumnNameNoThe database field name for the given property.None
CanManipulateNoWhen set to false, you will not be able to update this property when calling the associated endpoint. When set to false, the property will be able to be established when using the POST endpoint, but will not be able to be updated after that. This is managed by the DTOs if you want to manually adjust this.true
false for primary key
DefaultValueNoAllows you to add a default value to a property. Note that it should be entered exactly as you'd want it, so a string would be something like "My Default Value", a bool might be true, and an int might be 0None
ForeignKeyPropNameNoWhen adding an object linked by a foreign key, use ForeignKeyPropName to enter the name of the property that acts as the foreign keyNone

Example

This example would create a supplier entity with several properties. Note:

  • The SupplierId is marked as a primary key
  • We have normal and nullable primitives in the Type option
  • We have marked the properties as sortable and filterable
  • We have given a default value for IsVip
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: IsVip
        Type: bool?
        CanFilter: true
        CanSort: true
        DefaultValue: false

Example With Foreign Key

Now let's say that we had a Sale entity that has a ProductId property that acts as a foreign key to another 'Product' entity:

Entities:
  - Name: Sale
    Properties:
    - Name: SaleId
      IsPrimaryKey: true
      Type: int
      CanFilter: true
    - Name: ProductId
      Type: int
      CanFilter: true
    - Name: SaleDate
      Type: DateTimeOffset?
      CanFilter: true
    - Name: SaleAmount
      Type: int
      CanFilter: true

If we wanted to return the product in our responses, we could add an additional Product property of type Product that links to the primary key of ProductId in our Product entity:

If possible, it is recommended that you avoid returning the foreign key object directly in an entity response like this. Instead, have your front end call each necessary endpoint or build a domain object that build this out separately.

Entities:
  - Name: Sale
    Properties:
    - Name: SaleId
      IsPrimaryKey: true
      Type: int
      CanFilter: true
    - Name: ProductId
      Type: int
      CanFilter: true
    - Name: SaleDate
      Type: DateTimeOffset?
      CanFilter: true
    - Name: SaleAmount
      Type: int
      CanFilter: true
    - Name: Product
      Type: Product
      ForeignKeyPropName: ProductId

Note that adding foreign keys will currently break the Post and Update integration tests as described in issue #2.

Composite Keys

For the time being, composite keys can not be created using Craftsman commands. With that said, you are more than welcome to scaffold out an entity with one of the keys and then modify the generated entity, repository, tests, etc. to accommodate that composite key.