Understanding Metadata
Learn how to describe your application structure in metadata. From simple entities to complex relationships, see how MetaFirst transforms metadata into production-ready code.
1. The Simplest Example – A Minimal Entity
A single entity with only a primary key and a name. MetaFirst already generates database, services, WebAPI, and Admin UI from this.
| Entity | Field | Type | Attributes |
|---|---|---|---|
| ToDoList | Id | int | Key, Generated, SurrogateKey, DefVal=0, TestVal=1, Name=Name, Doc=Unique ToDoList Id|Primary key, AdminTheme=DataTables_Kai |
| ToDoList | Name | string | IsUnique, MaxLength=100, DefVal=, TestVal=ToDoListTestName, Doc=Unique todo list name |
Understanding the Structure
DbTableName=[AnotherTableName]HasColumnTypeKey Attributes Explained
| Field | Attribute | Description |
|---|---|---|
| Id | Key | Defines the Field as the (only) Primary key. Supported types: int, long, Guid, string |
| Id | Generated | Must be set for Surrogate keys and Guid keys |
| Id | SurrogateKey | Specifies that the Key is database generated. This is the recommended setting. Types: int or long |
| Id | DefVal=0 | Default value required for every property. Used in code for object construction. Use DbDefVal for database defaults |
| Id | TestVal=1 | Mandatory for properties. Used for automatically generating xUnit tests |
| Id | Name=Name | Defines the Property used for better naming. "MyTodoListInOctober" is clearer than an ID number |
| Id | Doc=... | Description of the entity. Used in code documentation |
| Id | AdminTheme | Currently mandatory for the first Entity. Choose your Admin theme (more themes coming) |
| Name | IsUnique | Ensures uniqueness. Creates database index for faster queries. Throws exception on duplicates |
| Name | MaxLength | Max length for string properties. Creates nvarchar(MaxLength) unless overridden by HasColumnType |
2. Activatable – Lifecycle Control
Activatable entities can be enabled or disabled without deleting data. MetaFirst generates filtering logic, UI toggles, and API behavior automatically.
| Entity | Field | Type | Attributes |
|---|---|---|---|
| ToDoList | Id | int | Key, Generated, SurrogateKey, Activatable, DefVal=0, TestVal=1, Name=Name, Doc=Unique ToDoList Id|Primary key, AdminTheme=DataTables_Kai |
| ToDoList | Name | string | IsUnique, MaxLength=100, DefVal=, TestVal=ToDoListTestName, Doc=Unique todo list name |
| ToDoList | Active | bool | DefVal=false, TestVal=true, Doc=If data is activated |
3. Audit – Tracking Data Changes
Audit fields track who created or modified data and when. Ideal for enterprise systems and compliance requirements.
| Entity | Field | Type | Attributes |
|---|---|---|---|
| ToDoList | Id | int | Key, Generated, SurrogateKey, Audit, DefVal=0, TestVal=1, Name=Name, Doc=Unique ToDoList Id|Primary key, AdminTheme=DataTables_Kai |
| ToDoList | Name | string | IsUnique, MaxLength=100, DefVal=, TestVal=ToDoListTestName, Doc=Unique todo list name |
| ToDoList | CreatedBy | string | MaxLength=100, DefVal=, TestVal=UnitTest, Doc=Data created by |
| ToDoList | CreatedDate | DateTime | FeFormat=yyyy-MM-ddTHH:mm:ss, DefVal=1900-01-01T00:00:00, TestVal=1900-01-01T00:00:00, Doc=Data creation date |
| ToDoList | ModifiedBy | string | MaxLength=100, DefVal=, TestVal=UnitTest, Doc=Data modified by |
| ToDoList | ModifiedDate | DateTime | FeFormat=yyyy-MM-ddTHH:mm:ss, DefVal=1900-01-01T00:00:00, TestVal=1900-01-01T00:00:00, Doc=Data modification date |
New Attribute: FeFormat
FeFormat defines the DateTime format for the Property. The database stores it as DateTime by default, or by a specific HasColumnType you define.
This format is especially important when exporting or importing data. When no format is specified, "1900-01-01T00:00:00" is used (ISO 8601 format).
4. Extendable / EAV – Dynamic Metadata
Extendable entities support dynamic properties using the EAV (Entity-Attribute-Value) model. MetaFirst hides all EAV complexity from client code.
| Entity | Field | Type | Attributes |
|---|---|---|---|
| ToDoList | Id | int | Key, Generated, SurrogateKey, Extendable, DefVal=0, TestVal=1, AttributeStore=TodoListAttribute, Name=Name, Doc=Unique ToDoList Id|Primary key, AdminTheme=DataTables_Kai |
| ToDoList | Name | string | IsUnique, MaxLength=100, DefVal=, TestVal=ToDoListTestName, Doc=Unique todo list name |
| ToDoList | AttribSchema | string | MaxLength=100, DefVal=None, TestVal=ToDoList_Extended, Options=None|ToDoList_Extended, Doc=ToDoList schema |
| ToDoList | Description | string | MaxLength=4000, AttribOf=ToDoList_Extended, AttribStoring=Big, DefVal=, TestVal=About the ToDoList, Doc=ToDoList detailed description |
EAV-Specific Attributes
| Field | Attribute | Description |
|---|---|---|
| Id | AttributeStore | Defines the table where EAV data is stored. Every store has a normal and a "Big" table with the same structure, only the Value field is larger in the Big table |
| AttribSchema | Options | Required for Extendable/EAV Entities. Defines all possible EAV-Schemas for the data item. Users can select a schema in the Admin for every new data item |
| Description | AttribOf | Specifies which schema this attribute belongs to. When "None" is specified, the data has no additional Schema Properties |
| Description | AttribStoring | Define the Small or Big store for the EAV-Attribute data |
5. Basic Relation – One-To-Many
A ToDoList can contain multiple ToDoItems. MetaFirst automatically generates foreign keys, navigation properties, optimized queries, API endpoints, and related Admin UI views.
| Entity | Field | Type | Attributes |
|---|---|---|---|
| Parent Entity: ToDoList | |||
| ToDoList | Id | int | Key, Generated, SurrogateKey, DefVal=0, TestVal=1, Name=Name, Doc=Unique ToDoList Id|Primary key, AdminTheme=DataTables_Kai |
| ToDoList | Name | string | IsUnique, MaxLength=100, DefVal=, TestVal=Todos in October, Doc=Unique todo list name |
| Child Entity: ToDoItem | |||
| ToDoItem | Id | int | Key, Generated, SurrogateKey, DefVal=0, TestVal=1, Name=Id, Doc=Unique ToDoItem Id|Primary key |
| ToDoItem | ToDoListId | int | ForeignKey, DefVal=0, TestVal=1, Doc=Reference to parent ToDoList |
| ToDoItem | Title | string | MaxLength=200, DefVal=, TestVal=Buy groceries, Doc=Item title |
| ToDoItem | IsCompleted | bool | DefVal=false, TestVal=false, Doc=Completion status |
Foreign Key Attribute
The ForeignKey attribute creates a relationship between entities. MetaFirst automatically:
- Generates database foreign key constraints
- Creates navigation properties in C# models
- Builds optimized LINQ queries with proper joins
- Generates API endpoints that respect relationships
- Creates Admin UI views showing parent-child relationships
Ready to try it yourself?
Download the free Education Edition and start generating your own metadata-driven applications. For complete details on all attributes and advanced features, check out the full documentation.