Skip to content

DbContexts

The dbContexts section allows you to define the database data contexts for your entities.

Here you configure all needed features for your entities administration at runtime, including: map entities with their database objects, define the objects relationships and data persistence.

Fields

A dbContext contains the following fields to be defined:

Name

The name of dbContext to be created.

Requirements Rules:

  • Is Required;
  • Must not be a Reserved Keyword;
  • Must start with a letter;
  • Must contains only letters, numbers and the underline char ('_');
  • Max length of 50 chars

Example:

1
2
DbContexts:
- Name: My_First_DbContext


DatabaseName

The name of database to which the dbContext refers.

Requirements Rules:

  • Is Required;
  • The name must be exist in Databases list in the current model;

Example:

1
2
3
DbContexts:
- Name: My_First_DbContext
  DatabaseName: My_First_Database


DefaultSchema

Specifies the database schema to be used for all tables, documents and objects whose schema is not specified at the creation time.

_NOTE: MySql does not support the EF Core concept of schemas. Therefore, this property will be ignored if it is informed for MySql instances. For more info, see the MySql Schema Glossary.

Requirements Rules:

  • Must start with a letter;
  • Must contains only letters, numbers and the underline char ('_');
  • Only allowed for relational database instance types;

Example:

1
2
3
4
DbContexts:
- Name: My_First_DbContext
  DatabaseName: My_First_Database
  DefaultSchema: my_schema


DbMappings

The list of entity mappings for this dbContext.

Requirements Rules:

  • DbMapping is allowed only for relational database instance types;
  • Each dbMapping must have an exclusive 'Name' property value;
  • Each dbMapping on list must follows rules as specified in DbMapping;

Example:

1
2
3
4
5
6
7
8
9
DbContexts:
- Name: My_First_DbContext
  DatabaseName: My_First_Database
  DefaultSchema: my_schema
  DbMappings:
  - Name: Entity01_Mapping
    ...
  - Name: Entity02_Mapping
    ...


Complete Example

See below for a complete example, containing all the properties for the DbContexts section.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
DbContexts:
- Name: My_First_DbContext
  DatabaseName: My_First_Database
  DefaultSchema: my_schema
  DbMappings:
  - Name: Entity01_DbMapping
    EntityName: My_First_Entity
    Table: My_First_Table
    Comment: Store the customer orders
    AlternateKeys:
    - [Property1]
    Indexes:
    - Properties: [Property2]
      IsUnique: true
    Properties:
    - PropertyName: Property1
      ColumnName: Table01_Column01
      Comment: Store the order number
    Relationships:
    - ChildEntityName: My_Second_Entity
      IsRequired: false
      Type: OneToOne
      ParentPropertyName: Prop_My_Second_Entity
      ChildPropertyName: Prop_My_First_Entity
      ForeignKeyProperty: Property01

Back to top