Table of Contents

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

modelType Type

Type of the model.

logger ILogger

Optional logger.

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

List<string>

Model properties that are not part of the schema.

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

T

Type to cast the model

CreateSchemaFields(ISchemaDataObject)

Creates schema fields and constraints for a model.

public void CreateSchemaFields(ISchemaDataObject schemaObj)

Parameters

schemaObj ISchemaDataObject

The 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

schemaObj ISchemaDataObject

The schema object.

ddlHelper IOrpheusDDLHelper

The ddl helper.

Returns

List<string>

GetFieldNameForProperty(PropertyInfo)

Helper function that returns the corresponding field name for a property.

public string GetFieldNameForProperty(PropertyInfo prop)

Parameters

prop PropertyInfo

The property info.

Returns

string

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

modelType Type

Returns

OrpheusModelHelper

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

modelType Type
logger ILogger

Returns

OrpheusModelHelper

IsSchemaProperty(PropertyInfo)

Helper function that returns true if the property is not actually part of the schema.

public bool IsSchemaProperty(PropertyInfo property)

Parameters

property PropertyInfo

The property.

Returns

bool

IterateModelProperties(ModelProperty)

Helper function to iterate through the model properties and calls the given callback, for each property.

public void IterateModelProperties(ModelProperty callback)

Parameters

callback ModelProperty

The 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

property PropertyInfo

The property.

callback PropertyAttribute

The callback method.