Class OrpheusModelHelper
- Namespace
- OrpheusCore
- Assembly
- OrpheusCore.dll
OrpheusModelHelper is a helper class that analyzes a model and can create primary-foreign keys and/or schema fields, when creating a schema.
public class OrpheusModelHelper : IOrpheusModelHelper
- Inheritance
-
OrpheusModelHelper
- Implements
- Inherited Members
Constructors
OrpheusModelHelper(Type, ILogger)
Initializes a new instance of the OrpheusModelHelper class. OrpheusModelHelper is a helper class that analyzes a model and can create primary-foreign keys and/or schema fields, when creating a schema.
public OrpheusModelHelper(Type modelType, ILogger logger = null)
Parameters
Properties
CustomFieldNameProperties
public Dictionary<string, string> CustomFieldNameProperties { get; }
Property Value
- Dictionary<string, string>
Model properties that have an explicitly set field name.
ForeignKeys
public Dictionary<string, IForeignKey> ForeignKeys { get; }
Property Value
- Dictionary<string, IForeignKey>
Model's foreign keys.
ModelProperties
public PropertyInfo[] ModelProperties { get; }
Property Value
- PropertyInfo[]
Model's properties.
PrimaryCompositeKeys
public List<IOrpheusBaseCompositeKeyAttribute> PrimaryCompositeKeys { get; }
Property Value
- List<IOrpheusBaseCompositeKeyAttribute>
Model's composite primary keys.
PrimaryKeys
public Dictionary<string, IPrimaryKey> PrimaryKeys { get; }
Property Value
- Dictionary<string, IPrimaryKey>
Model's primary keys.
SQLName
public string SQLName { get; }
Property Value
- string
Model's SQLName. Defaults to the model's type name.
SQLServerSchemaName
public string SQLServerSchemaName { get; }
Property Value
- string
SQL server's schema name.
SchemaIgnoreProperties
public List<string> SchemaIgnoreProperties { get; }
Property Value
UniqueCompositeKeys
public List<IOrpheusBaseCompositeKeyAttribute> UniqueCompositeKeys { get; }
Property Value
- List<IOrpheusBaseCompositeKeyAttribute>
Model's composite unique keys.
UniqueKeys
public Dictionary<string, IUniqueKey> UniqueKeys { get; }
Property Value
- Dictionary<string, IUniqueKey>
Model's unique keys.
Methods
CreateInstance<T>()
Creates an instance of the model and typecasts it to the given type.
public T CreateInstance<T>()
Returns
- T
An instance of 'T'
Type Parameters
TType to cast the model
CreateSchemaFields(ISchemaDataObject)
Creates schema fields and constraints for a model.
public void CreateSchemaFields(ISchemaDataObject schemaObj)
Parameters
schemaObjISchemaDataObjectThe schema object.
GetAlterDDLCommands(ISchemaDataObject, IOrpheusDDLHelper)
Creates a list of SQL ALTER commands, based on the differences between the current version of the model and the current version of the corresponding db table.
public List<string> GetAlterDDLCommands(ISchemaDataObject schemaObj, IOrpheusDDLHelper ddlHelper)
Parameters
schemaObjISchemaDataObjectThe schema object.
ddlHelperIOrpheusDDLHelperThe ddl helper.
Returns
GetFieldNameForProperty(PropertyInfo)
Helper function that returns the corresponding field name for a property.
public string GetFieldNameForProperty(PropertyInfo prop)
Parameters
propPropertyInfoThe property info.
Returns
GetOrAdd(Type)
Returns a cached OrpheusModelHelper for the given model type. The cached instance has no logger; use the overload with ILogger if logging is needed.
public static OrpheusModelHelper GetOrAdd(Type modelType)
Parameters
modelTypeType
Returns
GetOrAdd(Type, ILogger)
Returns a cached OrpheusModelHelper for the given model type, with the provided logger attached.
public static OrpheusModelHelper GetOrAdd(Type modelType, ILogger logger)
Parameters
Returns
IsSchemaProperty(PropertyInfo)
Helper function that returns true if the property is not actually part of the schema.
public bool IsSchemaProperty(PropertyInfo property)
Parameters
propertyPropertyInfoThe property.
Returns
IterateModelProperties(ModelProperty)
Helper function to iterate through the model properties and calls the given callback, for each property.
public void IterateModelProperties(ModelProperty callback)
Parameters
callbackModelPropertyThe callback method.
IteratePropertyAttributes(PropertyInfo, PropertyAttribute)
Helper function to iterate through the property's attributes and calls the given callback, for each attribute.
public void IteratePropertyAttributes(PropertyInfo property, PropertyAttribute callback)
Parameters
propertyPropertyInfoThe property.
callbackPropertyAttributeThe callback method.