Entities File Settings

Settings for scaffolding out an entity for your Web API.

Entities

A 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
FeaturesYesThis is a list of features that you want to add for a particular entity.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

A 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 ?. All standard C# data types can be used here. You even do custom properties like classes that act as foreign keys for instance.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

Features

NameRequiredDescriptionDefault
TypeYesThe type of feature you want to add. The accepted values are AdHoc, GetRecord, GetList, DeleteRecord, UpdateRecord, PatchRecord, AddRecord, and CreateRecord (same as AddRecord but available as an alias in case you can't remember!)None

GetRecord, GetList, DeleteRecord, UpdateRecord, PatchRecord, and AddRecord are all standard CRUD features along with their endpoints and associated tests.

ℹ DTOs, validators, profiles and functional test routes associated to all features will be added regardless of whether or not a given feature was added. This is due to the complexity of all the minute management around handling these so dynamically. Feel free to delete whatever you're not using.

Ad Hoc Features

You can also add ad hoc skeletons with the AdHoc type. For AdHoc features, there's a bit more that needs to be done. In addition to Type above, you'll want to provide the below:

NameRequiredDescriptionDefault
NameYesThe name of the feature. This is the name of the feature's method and would generally be something like AddCustomer or GetCustomer.None
CommandYesThe name of the command. This is the name of the feature's class and would generally be something like AddCustomerCommand or GetCustomerQuery.[NAME]Command
EntityPluralNo (but recommended)The plural name of the entity that the feature will be added to (should match the name in the Domain directory). You can leave this blank to add it to the Domain directory directly.""
ResponseTypeNoIs the type of response that this command will return. This could be any C# type that you want, or even a custom type if you want, but in that case, you'll need to add a using statement for it manually.bool

You can also add AdHoc features after the fact using the add:feature command.

Entity 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
  • We are adding all the available features except for PatchRecord. We're also adding an AdHoc feature for use for batch adding suppliers.
Entities:
  - Name: Supplier
    Features:
    - Type: AddRecord
    - Type: GetRecord
    - Type: GetList
    - Type: UpdateRecord
    - Type: DeleteRecord
    - Type: AdHoc
      Name: BatchAddSuppliers
      Command: BatchAddSuppliersCommand
      EntityPlural: Suppliers
    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

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.