Class DefinitionFactory
Factory for creating database model definitions used in Umbraco CMS persistence.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions
Assembly: Umbraco.Infrastructure.dll
Syntax
public static class DefinitionFactory
Methods
View SourceGetColumnDefinition(Type, PropertyInfo, string, string, ISqlSyntaxProvider)
Creates a ColumnDefinition for the specified property of a model type by inspecting its attributes and metadata.
Declaration
public static ColumnDefinition GetColumnDefinition(Type modelType, PropertyInfo propertyInfo, string columnName, string tableName, ISqlSyntaxProvider sqlSyntax)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | modelType | The type of the model containing the property. |
| PropertyInfo | propertyInfo | The System.Reflection.PropertyInfo representing the property to map as a database column. |
| string | columnName | The name of the column in the database. |
| string | tableName | The name of the table the column belongs to. |
| ISqlSyntaxProvider | sqlSyntax | The SQL syntax provider used for database-specific SQL generation. |
Returns
| Type | Description |
|---|---|
| ColumnDefinition | A ColumnDefinition describing the column's database mapping, including type, nullability, primary key, size, constraints, and other settings as determined by attributes (such as NullSettingAttribute, SpecialDbTypeAttribute, PrimaryKeyColumnAttribute, LengthAttribute, and ConstraintAttribute) applied to the property. |
GetForeignKeyDefinition(Type, PropertyInfo, ForeignKeyAttribute, string, string)
Creates a ForeignKeyDefinition that describes a foreign key relationship for the specified model property.
Declaration
public static ForeignKeyDefinition GetForeignKeyDefinition(Type modelType, PropertyInfo propertyInfo, ForeignKeyAttribute attribute, string columnName, string tableName)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | modelType | The System.Type of the model declaring the foreign key property. |
| PropertyInfo | propertyInfo | The System.Reflection.PropertyInfo for the property representing the foreign key in the model. |
| ForeignKeyAttribute | attribute | The ForeignKeyAttribute providing metadata about the referenced table and column. |
| string | columnName | The name of the column in the current (foreign) table that holds the foreign key value. |
| string | tableName | The name of the current (foreign) table containing the foreign key column. |
Returns
| Type | Description |
|---|---|
| ForeignKeyDefinition | A ForeignKeyDefinition that specifies the foreign key constraint, including the foreign and primary tables, columns, and referential actions. |
GetIndexDefinition(Type, PropertyInfo, IndexAttribute, string, string)
Creates an IndexDefinition based on the provided model type, property, and index attribute.
Declaration
public static IndexDefinition GetIndexDefinition(Type modelType, PropertyInfo propertyInfo, IndexAttribute attribute, string columnName, string tableName)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | modelType | The model System.Type that contains the property. |
| PropertyInfo | propertyInfo | The System.Reflection.PropertyInfo representing the property to index. |
| IndexAttribute | attribute | The IndexAttribute containing index configuration. |
| string | columnName | The name of the column to be indexed. |
| string | tableName | The name of the table containing the column. |
Returns
| Type | Description |
|---|---|
| IndexDefinition | An IndexDefinition describing the index. |
GetTableDefinition(Type, ISqlSyntaxProvider)
Generates a TableDefinition for the specified model type, using the provided SQL syntax provider. The method inspects the model type's properties and associated attributes (such as NPoco.TableNameAttribute, NPoco.ColumnAttribute, ForeignKeyAttribute, IndexAttribute, NPoco.IgnoreAttribute, and NPoco.ResultColumnAttribute) to determine the table name, columns, foreign keys, and indexes.
Declaration
public static TableDefinition GetTableDefinition(Type modelType, ISqlSyntaxProvider sqlSyntax)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | modelType | The model System.Type to generate the table definition for. |
| ISqlSyntaxProvider | sqlSyntax | The SQL syntax provider used to generate database-specific SQL. |
Returns
| Type | Description |
|---|---|
| TableDefinition | A TableDefinition representing the database table structure, including columns, foreign keys, and indexes, for the specified model type. |