本文整理汇总了C#中IDbHelper.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# IDbHelper.GetProperties方法的具体用法?C# IDbHelper.GetProperties怎么用?C# IDbHelper.GetProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbHelper
的用法示例。
在下文中一共展示了IDbHelper.GetProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateClass
private void PopulateClass(ModelClass cls, IDbConnection connection, IDbHelper helper)
{
if (cls != null && connection != null)
{
// Relations to this class (this class has the primary key)
List<Relation> relationsTo = helper.GetPKRelations(cls);
// If the other side of the relation (FK part) is not in our model, we won't
// need the relation at all
_manager.FilterPKRelations(relationsTo);
// Relations from this class (this class has the foreign key)
List<Relation> relationsFrom = helper.GetFKRelations(cls);
// If the other side of the relation (PK part) is not in our model, we won't
// need the relation at all
_manager.FilterFKRelations(relationsFrom);
// Properties
List<Column> columns = helper.GetProperties(cls);
if (columns != null && columns.Count > 0)
{
List<Column> specialColumns = new List<Column>();
List<Column> ordinaryColumns = new List<Column>();
foreach(Column column in columns)
{
if (column.Primary ||
(column.ForeignConstraints.Count > 0 &&
(Relation.GetCountOfMatchingRelations(relationsTo, column.ForeignConstraints) > 0 ||
Relation.GetCountOfMatchingRelations(relationsFrom, column.ForeignConstraints) > 0)
)
)
{
specialColumns.Add(column);
}
else
{
ordinaryColumns.Add(column);
}
}
if (_manager.SortProperties)
{
ordinaryColumns.Sort(new ColumnComparer());
specialColumns.Sort(new ColumnComparer());
}
// Keys
List<Column> primaryKeys = null;
if (specialColumns.Count > 0)
{
primaryKeys = Column.FindPrimaryKeys(specialColumns);
if (primaryKeys != null && primaryKeys.Count > 0)
{
// Create primary and composite keys
if (primaryKeys.Count == 1)
{
ModelProperty keyProperty = _manager.NewPrimaryKey(cls, primaryKeys[0]);
keyProperty.ColumnType = helper.GetNHibernateType(primaryKeys[0].DataType);
SetGenerator(keyProperty);
}
else
{
string keyClassName = cls.Name + Common.CompositeClassNameSuffix;
foreach(Column key in primaryKeys)
{
ModelProperty keyProperty = _manager.NewCompositeKey(cls, key, keyClassName);
keyProperty.ColumnType = helper.GetNHibernateType(key.DataType);
SetGenerator(keyProperty);
}
}
}
}
foreach (var column in ordinaryColumns)
{
_manager.NewProperty(cls, column).ColumnType = helper.GetNHibernateType(column.DataType);
}
if (relationsTo != null && relationsTo.Count > 0)
{
foreach(Relation relation in relationsTo)
{
relation.PrimaryModelClass = cls;
}
}
_relations.AddRange(relationsTo);
if (relationsFrom != null && relationsFrom.Count > 0)
{
foreach(Relation relation in relationsFrom)
{
relation.ForeignModelClass = cls;
}
_relations.AddRange(relationsFrom);
// To define many to many and one to one, we need to know the pattern of foreign keys.
if (primaryKeys != null && primaryKeys.Count > 0)
{
foreach(Column key in primaryKeys)
{
Relation relation = Relation.GetForeginColumn(relationsFrom, key);
//.........这里部分代码省略.........