ID3Context Class
The interface that holds database specific data and functions to be able to map entity-database names and relations, holds your custom naming conventions for IDs and DTOs, holds some conventions for creating SQL for a specific database system...
namespace KLO128.D3ORM.Common
{
public interface ID3Context
}
Assembly
KLO128.D3ORM.Common
Base Types
Object
Properties
DatabaseType
DatabaseType DatabaseType { get; }
Description
The database system this context is created for.
DateFormat
string DateFormat { get; }
Description
Database System Date Format: yyyy-MM-dd is the default value.
DbIdColumnFormat
string DbIdColumnFormat { get; }
Description
Name Format of Id Columns
i.e.: {0}_id
DtoPatternFormat
string DtoPatternFormat { get; }
Description
DTO pattern supporting regular expression syntax. Must contain a placeholder for an entity name: {0}
i.e.: {0}DTO
EntityIdPropFormat
string EntityIdPropFormat { get; }
Description
Name Format of Id Properties
i.e.: {0}Id
EntityMappings
Dictionary<Type, EntityMapping> EntityMappings { get; set; }
Description
The dictionary (EntityType -> EntityMapping) for a quick indexed access to EntityMapping of each type.
EntitiesNameSpace
string EntitiesNameSpace { get; }
Description
The namespace of the Entities
ExceptionalDbColumnNames
Dictionary<string, string> ExceptionalDbColumnNames { get; set; }
Description
Defines non-standard property -> column name mappings, which cannot be guessed. I.e.: GUIDExpirationDate would be converted from camel case into MySQL or Oracle name as: g_u_i_d_expiration_date. Important also for other DbSystems using camel case names if a column or table name is not the same as a property name.
IdefStart
char IdefStart { get; }
Description
The start identifier character, typically for MySQL: ` or for MSSQL, SQLite: [ ### IdefEnd
NotEqualOperator
string NotEqualOperator { get; }
Description
The target database not equal operator string - it differs across database systems: != or <>
NotFunction
string? NotFunction { get; }
Description
Specifies NOT(condition) function name. If null then (condition) = 0 is used.
OtherModelNamespaces
public List<string> OtherModelNamespaces { get; set; }
Description
Defines other namespaces (other than query root's namespace) where to find entity or DTO.
If the name of Entity or DTO is not unique and not placed in the same namespace as the query root, the instance of type from the first namespace found sequentially is made when resolving a query result.
UseAutoIncrement
bool UseAutoIncrement { get; set; }
Description
Indicates if to skip populating of an id primary key property (if it is populated by itself in the database using the auto-increment principle).
true by default
UseFullIdOrderBy
bool UseFullIdOrderBy { get; set; }
Description
Indicates if to include all primary keys into ORDER BY expression even if there are no other "many to one" or "one to many" sorts from a current "one to many" context select group till the end of the select.
It can slightly influent the performance depending on a database system... MySQL D3Context's value is true by default.
Methods
ConcatDbName(..)
string ConcatDbName(string dbName, string text, bool asPrefix);
Description
Concatenates the text (usual usage: asPrefix == true) to the database dbName with persistence of naming conventions and identifier start-end quotes.
Return Type
string
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | dbName | string | original database name | |
2. | text | string | text to concatenate | |
3. | asPrefix | bool | If true, the text is inserted at the start of the dbName after IdefStart character, otherwise the text is inserted at the end of the dbName before IdefEnd character. |
ConvertsDbValue(..)
object? ConvertsDbValue(object value, Type propertyType);
Description
Converts the database value into the target propertyType.
Return Type
object?
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | value | object | value to convert | |
2. | propertyType | Type | target data type |
CreateAnonymousConnection(..)
IDbConnection CreateAnonymousConnection(Type connectionType, string connectionString);
Description
Creates an anonymous connection outside of any IoC container - useful for asynchronous bulk operations, which needs to continue even if request ends.
Return Type
IDbConnecttion
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | connectionType | Type | The database connection type that implements IDbConnection. | |
2. | connectionString | string | database connection string |
GetDbNameQuoted(..)
string GetDbNameQuoted(string name);
Description
Gets a database name from the name including IdefStart and IdefEnd chars.
Return Type
string
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | name | string | name of any kind |
GetEntityNameFromDTO(..)
string GetEntityNameFromDTO(string dtoName);
Description
Gets the entity name from the dtoName.
Return Type
string?
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | dtoName | string | DTO name |
GetIdPropName(..)
string GetIdPropName(string entityName);
Description
Gets the id property name from the entityName.
Return Type
string
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | entityName | string | entity name |
GetLastInsertedRowIdCommandText(..)
string GetLastInsertedRowIdCommandText(string? entityName);
Description
Retrieves a database script for obtaining the last inserted row id.
Return Type
string
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | entityName | string | entity name |
IsEntityIdProp(..)
bool IsEntityIdProp(string propName);
Description
Determines if the propName is an id like property name.
Return Type
bool
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | propName | string | property name |
TryGetEntityNameFromIdProp(..)
string? TryGetEntityNameFromIdProp(string propName);
Description
If the propName is id like, returns its entity name, otherwise returns null.
Return Type
string?
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | propName | string | property name |